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

FEATURE : Add `strictyaml` command-line tool #55

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@9999years
Copy link

9999years commented Apr 11, 2019

Adds a strictyaml binary which parses input files and prints errors, useful for linting YAML files:

$ strictyaml --no-symbols site.yml roles/common/tasks/xcode.yml
While scanning
  in "site.yml", line 5, column 9:
      flow: { flow: val }
            ^ (line: 5)
Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)
  in "site.yml", line 5, column 10:
      flow: { flow: val }
             ^ (line: 5)
site.yml contained errors
roles/common/tasks/xcode.yml validated successfully
Encountered 1 error

$ cat roles/common/tasks/xcode.yml | strictyaml -
☑ <stdin>
All files validated successfully

Future work: Schema validation would be nice, and it would be great to report all errors in a file, rather than just the first one, but this is very useful on its own.

$ hk lint; hk bdd cli
RUNNING strictyaml cli in /home/u/fall18/rebeccaturner/projects/strictyaml/hitch/story/cli.story ...
[...]
Successfully built strictyaml
Installing collected packages: strictyaml
Successfully installed strictyaml-1.0.1
SUCCESS in 13.7 seconds.
FEATURE : Add `strictyaml` command-line tool
Adds a `strictyaml` binary which parses input files and prints errors;
useful for linting YAML files:

    $ strictyaml --no-symbols site.yml roles/common/tasks/xcode.yml
    While scanning
      in "site.yml", line 5, column 9:
          flow: { flow: val }
                ^ (line: 5)
    Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)
      in "site.yml", line 5, column 10:
          flow: { flow: val }
                 ^ (line: 5)
    site.yml contained errors
    roles/common/tasks/xcode.yml validated successfully
    Encountered 1 error

    $ cat roles/common/tasks/xcode.yml | strictyaml -
    ☑ <stdin>
    All files validated successfully

Also extends `hitch/engine.py` to support running shell commands and
examining their output.
@crdoconnor

This comment has been minimized.

Copy link
Owner

crdoconnor commented Apr 14, 2019

Hi @9999years Thanks for your PR and sorry for the delay getting back to you (busy weekend).

Thanks also for BDD'ing this with the framework. I'm impressed (you're the first person to do this so far).

I've been pondering this new feature over the weekend and while I like the feature a lot I feel like it overstretches the remit of what the strictyaml library should provide. I would like to have a CLI tool of some kind as part of a different library and then include it as part of a suite of StrictYAML tools.

Would it be possible to separate this out into a separate library (e.g. strictyaml-cli) ? I can then link to the library near the top of the README.

@9999years

This comment has been minimized.

Copy link
Author

9999years commented Apr 17, 2019

Yes, that sounds reasonable. Would you be willing to take ownership over the library once I package / complete it?

Further, do you think exposing some API for all the errors in a file would be doable / easy? I didn't look at the parser code in a lot of depth, but I didn't see an obvious place it would be exposed.

@crdoconnor

This comment has been minimized.

Copy link
Owner

crdoconnor commented Apr 20, 2019

Yes, that sounds reasonable. Would you be willing to take ownership over the library once I package / complete it?

If it demonstrates some level of popularity/usage, yes. I don't currently have a use for it but if many others do I'd be delighted to maintain it. I'd be equally happy to promote your role in it.

Further, do you think exposing some API for all the errors in a file would be doable / easy? I didn't look at the parser code in a lot of depth, but I didn't see an obvious place it would be exposed.

Unfortunately not right now. The code is architected to raise an exception on the first issue it encounters and stop. Even more unfortunately, the library is also dependent upon another library (ruamel.yaml) that follows the same behavior when doing the raw parsing. Long term - I would like to remove the dependency on this library #56 but that's also quite a lot of work.

Moreover, since I couldn't see a pressing need for this feature (it was raised in #15 but as far as I could tell it was raised as a nice to have), I'm a bit reticent to do all this underpinning architectural work to make it possible if that is the case. I typically run the parser -> encounter errors -> fix them -> run the parser again -> encounter errors again -> fix them -> run the parser until everything passes and this workflow is currently accommodated. I assume that most others do the same.

That said, I always love to hear use cases and if there is one that demonstrates a clear and pressing need for this feature I'd be happy to move towards implementing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.