epage / clapng

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
0 stars 0 forks source link

Use Serde to parse YAML input #70

Open epage opened 2 years ago

epage commented 2 years ago

Issue by dtolnay Thursday Feb 16, 2017 at 05:52 GMT Originally opened as https://github.com/clap-rs/clap/issues/853


The errors from clap when my YAML isn't perfect are far less helpful than they could be. This makes it difficult to iterate on a YAML input.

Using Serde to read the YAML, errors would be able to provide the line, column, and property path at which the error occurs.

Steps to reproduce the issue


diff --git a/examples/17_yaml.yml b/examples/17_yaml.yml
index 4e55891..7226619 100644
--- a/examples/17_yaml.yml
+++ b/examples/17_yaml.yml
@@ -28,7 +28,7 @@ args:
     - flag:
         help: demo flag argument
         short: F
-        multiple: true
+        multiple: tru
         global: true
         # Conflicts, mutual overrides, and requirements can all be defined as a
         # list, where the key is the name of the other argument

Actual clap error

failed to convert YAML String("tru") value to a string

(this seems like a bug)

Serde-style error

args[2].flag.multiple: invalid type: string "tru", expected a boolean at line 31 column 19


diff --git a/examples/17_yaml.yml b/examples/17_yaml.yml
index 4e55891..5b6ee43 100644
--- a/examples/17_yaml.yml
+++ b/examples/17_yaml.yml
@@ -9,7 +9,7 @@ settings:

 # All Args must be defined in the 'args:' list where the name of the arg, is the
 # key to a Hash object
-args:
+arguments:
     # The name of this argument, is 'opt' which will be used to access the value
     # later in your Rust code
     - opt:

Current clap error

Serde-style error

unknown field `arguments`, expected one of `name`, `version`, `about`, `author`, `settings`, `args`, `subcommands`, `groups` at line 12 column 1


diff --git a/examples/17_yaml.yml b/examples/17_yaml.yml
index 4e55891..a1fc412 100644
--- a/examples/17_yaml.yml
+++ b/examples/17_yaml.yml
@@ -67,7 +67,7 @@ args:
 subcommands:
     # The nae of this subcommand will be 'subcmd' which can be accessed in your
     # Rust code later
-    - subcmd:
+    subcmd:
         about: demos subcommands from yaml
         version: "0.1"
         author: Kevin K. <kbknapp@gmail.com>

Current clap error

Serde-style error

subcommands: invalid type: map, expected a list of subcommands at line 70 column 5

epage commented 2 years ago

Comment by kbknapp Thursday Feb 16, 2017 at 14:40 GMT


Thanks for the detailed write up! I'm 100% for this if it can be made in a backwards compatible way, if not 3.x shouldn't be too far on the horizon and would accept a PR to the 3x-dev branch.

I'll mark this as "help wanted" simply because my bandwidth is limited right now with work and would be more than willing to take a look at a PR on the matter. Once I knock out a few more issues and my bandwidth opens back up, I'll take a swing at implementing this if it hasn't been done already :wink:

epage commented 2 years ago

Comment by kbknapp Sunday Jul 22, 2018 at 01:14 GMT


Blocker: https://github.com/dtolnay/serde-yaml/issues/94

epage commented 2 years ago

Comment by epage Tuesday Jul 20, 2021 at 17:26 GMT


https://github.com/clap-rs/clap/issues/1041 would help with the lifetime blocker