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

Group commands in CLI #1692

Merged
merged 4 commits into from
Mar 2, 2020
Merged

Conversation

joneshf
Copy link
Collaborator

@joneshf joneshf commented Mar 1, 2020

As mentioned in #1686, grouping commands should make using the CLI a bit easier. This PR changes the output from:

Old output of dhall --help
$ dhall --help
Usage: dhall ([version] | [resolve] | [type] | [normalize] | [repl] | [diff] |
             [hash] | [lint] | [tags] | [format] | [freeze] | [encode] |
             [decode] | [text] | [to-directory-tree] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Available commands:
  version                  Display version
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  lint                     Improve Dhall code by using newer language features
                           and removing dead code
  tags                     Generate etags file
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree

to:

New output of dhall --help
$ dhall --help
Usage: dhall ([format] | [freeze] | [lint] | [text] | [to-directory-tree] |
             [resolve] | [type] | [normalize] | [encode] | [decode] | [repl] |
             [diff] | [hash] | [tags] | [version] | [haskell-syntax-tree] |
             [--file FILE] [--output FILE] [--annotate] [--alpha] [--no-cache]
             [--version]) [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  tags                     Generate etags file
  version                  Display version

Debugging this interpreter
  haskell-syntax-tree      Output the parsed syntax tree (for debugging)

cc @sjakobi

There are currently 15 subcommands for the `dhall` binary. This is great
because it means the `dhall` binary is full of features. It's not so
great because trying to figure out what to do is non-trivial. We start
grouping commands so we can provide a bit of guidance on what people
might want to do.

The previous `--help` output looked like:

```console
$ dhall --help
Usage: dhall ([version] | [resolve] | [type] | [normalize] | [repl] | [diff] |
             [hash] | [lint] | [tags] | [format] | [freeze] | [encode] |
             [decode] | [text] | [to-directory-tree] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Available commands:
  version                  Display version
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  lint                     Improve Dhall code by using newer language features
                           and removing dead code
  tags                     Generate etags file
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree
```

This new output looks like:
```console
$ dhall --help
Usage: dhall ([version] | [resolve] | [type] | [normalize] | [repl] | [diff] |
             [hash] | [lint] | [tags] | [format] | [freeze] | [encode] |
             [decode] | [text] | [to-directory-tree] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Miscellaneous
  version                  Display version

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions

Manipulate Dhall code
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Miscellaneous
  tags                     Generate etags file

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree
```

There's still work to do: actually grouping the subcommands, and
displaying the debugging subcommand. But, this gets us on the path.
The way `optparse-applicative` works with command groups is by grouping
adjacent commands together. It doesn't traverse the entire graph and
build groups. We have to move the commands where we want them so it'll
produce the groups.

This is better for us because it means we can display our groups in the
order we want.

The help output changes from:

```console
$ dhall --help
Usage: dhall ([version] | [resolve] | [type] | [normalize] | [repl] | [diff] |
             [hash] | [lint] | [tags] | [format] | [freeze] | [encode] |
             [decode] | [text] | [to-directory-tree] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Miscellaneous
  version                  Display version

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions

Manipulate Dhall code
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Miscellaneous
  tags                     Generate etags file

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree
```

to:

```console
$ dhall --help
Usage: dhall ([format] | [freeze] | [lint] | [text] | [to-directory-tree] |
             [resolve] | [type] | [normalize] | [encode] | [decode] | [repl] |
             [diff] | [hash] | [tags] | [version] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  tags                     Generate etags file
  version                  Display version
```

This is much easier to understand, and should help direct people to the
right place. If we find that the groups should change, we can always do
that.
Now that we can describe groups of subcommands, we can describe the
subcommands that are for internal use only. These commands should not be
depended upon, and may change without warning. We might want to provide
more of a description around there.

The help output goes from:

```console
$ dhall --help
Usage: dhall ([format] | [freeze] | [lint] | [text] | [to-directory-tree] |
             [resolve] | [type] | [normalize] | [encode] | [decode] | [repl] |
             [diff] | [hash] | [tags] | [version] | [--file FILE]
             [--output FILE] [--annotate] [--alpha] [--no-cache] [--version])
             [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  tags                     Generate etags file
  version                  Display version
```

to:

```console
$ dhall --help
Usage: dhall ([format] | [freeze] | [lint] | [text] | [to-directory-tree] |
             [resolve] | [type] | [normalize] | [encode] | [decode] | [repl] |
             [diff] | [hash] | [tags] | [version] | [haskell-syntax-tree] |
             [--file FILE] [--output FILE] [--annotate] [--alpha] [--no-cache]
             [--version]) [--explain] [--plain] [--ascii] [--censor]
  Interpreter for the Dhall language

Available options:
  -h,--help                Show this help text
  --file FILE              Read expression from a file instead of standard input
  --output FILE            Write result to a file instead of standard output
  --annotate               Add a type annotation to the output
  --alpha                  α-normalize expression
  --no-cache               Handle protected imports as if the cache was empty
  --version                Display version
  --explain                Explain error messages in more detail
  --plain                  Disable syntax highlighting
  --ascii                  Format code using only ASCII syntax
  --censor                 Hide source code in error messages

Manipulate Dhall code
  format                   Standard code formatter for the Dhall language
  freeze                   Add integrity checks to remote import statements of
                           an expression
  lint                     Improve Dhall code by using newer language features
                           and removing dead code

Generate other formats from Dhall
  text                     Render a Dhall expression that evaluates to a Text
                           literal
  to-directory-tree        Convert nested records of Text literals into a
                           directory tree

Interpret Dhall
  resolve                  Resolve an expression's imports
  type                     Infer an expression's type
  normalize                Normalize an expression

Convert Dhall to and from its binary representation
  encode                   Encode a Dhall expression to binary
  decode                   Decode a Dhall expression from binary

Miscellaneous
  repl                     Interpret expressions in a REPL
  diff                     Render the difference between the normal form of two
                           expressions
  hash                     Compute semantic hashes for Dhall expressions
  tags                     Generate etags file
  version                  Display version

Debugging this interpreter
  haskell-syntax-tree      Output the parsed syntax tree (for debugging)
```

N.B. There's a new section at the end for debugging.
Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this! 🙂

@joneshf
Copy link
Collaborator Author

joneshf commented Mar 2, 2020

My pleasure!

It's been a while since I've made a PR here (have I ever?). What's the merge policy again? Do we wait three days or something before merging?

@Gabriella439
Copy link
Collaborator

@joneshf: You can merge once you have an approval

Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers! :)

dhall/src/Dhall/Main.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Main.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Main.hs Outdated Show resolved Hide resolved
As noticed in review, we want to keep indentation consistent, so we
reformat this to be four spaces instead of two.
Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Feel free to merge by hand, or apply the "merge me" button to let mergify take care of that.

@joneshf
Copy link
Collaborator Author

joneshf commented Mar 2, 2020

Thanks for the speedy reviews!

@mergify mergify bot merged commit 195c440 into dhall-lang:master Mar 2, 2020
@joneshf joneshf deleted the joneshf/group-commands branch March 2, 2020 14:26
@sjakobi sjakobi mentioned this pull request Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants