Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Serde to parse YAML input #853

Closed
dtolnay opened this issue Feb 16, 2017 · 4 comments
Closed

Use Serde to parse YAML input #853

dtolnay opened this issue Feb 16, 2017 · 4 comments
Labels
C-enhancement Category: Raise on the bar on expectations

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Feb 16, 2017

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

  • Introduce a typo in examples/17_yaml.yml (some example below)
  • cargo run --features yaml --example 17_yaml

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

  • None, silently ignores everything I wrote

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

  • None, silently ignores my subcommand

Serde-style error

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

@kbknapp
Copy link
Member

kbknapp commented Feb 16, 2017

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 😉

@kbknapp kbknapp added C: yaml parser C-enhancement Category: Raise on the bar on expectations labels Feb 16, 2017
@kbknapp kbknapp added this to the serde milestone Mar 27, 2017
@kbknapp kbknapp mentioned this issue Aug 22, 2017
87 tasks
@kbknapp kbknapp modified the milestones: serde, v3-alpha1 Feb 2, 2018
@kbknapp
Copy link
Member

kbknapp commented Jul 22, 2018

Blocker: dtolnay/serde-yaml#94

@epage
Copy link
Member

epage commented Jul 20, 2021

#1041 would help with the lifetime blocker

@epage
Copy link
Member

epage commented Dec 8, 2021

We have decided to deprecate the YAML API. For more details, see #3087. If there is interest in a YAML API, it will likely be broken out into a clap_yaml and developed independent from the core of clap.

@epage epage closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

3 participants