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

Add CLI tool #523

Merged
merged 8 commits into from Feb 25, 2024
Merged

Add CLI tool #523

merged 8 commits into from Feb 25, 2024

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Feb 24, 2024

Closes #479, CC @danielbayley & @antonmedv

Here's the npx yaml -h output, as currently implemented. I'm still contemplating a few additions like a node style normaliser, and the docs will need an update.

yaml: A command-line YAML processor and inspector

Reads stdin and writes output to stdout and errors & warnings to stderr.

Usage:
  yaml          Process a YAML stream, outputting it as YAML
  yaml cst      Parse the CST of a YAML stream
  yaml lex      Parse the lexical tokens of a YAML stream
  yaml valid    Validate a YAML stream, returning 0 on success

Options:
  --help, -h    Show this message.
  --json, -j    Output JSON.

Additional options for bare "yaml" command:
  --doc, -d     Output pretty-printed JS Document objects.
  --single, -1  Require the input to consist of a single YAML document.
  --strict, -s  Stop on errors.
  --visit, -v   Apply a visitor to each document (requires a path to import)
  --yaml 1.1    Set the YAML version. (default: 1.2)

@eemeli
Copy link
Owner Author

eemeli commented Feb 24, 2024

Added a --visit option. With that, you can define a visitor like:

// strip-styles.mjs
export default {
  Collection(_, node) {
    delete node.flow
  },
  Scalar(_, node) {
    delete node.format
    delete node.type
  }
}

and then apply it:

echo '{"hello":"world"}' | npx yaml --visit ./strip-styles.mjs

for this output:

hello: world

@eemeli eemeli marked this pull request as ready for review February 25, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should a basic CLI be included?
1 participant