Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Subcommands cleanup #317

Merged
merged 1 commit into from
Jan 31, 2020
Merged

Conversation

curiousleo
Copy link
Collaborator

@curiousleo curiousleo commented Jan 31, 2020

Overview

Just a little cleanup before we go to 1.0.

See 84fa275 commit message.

Checklist

  • Updated the documentation (code documentation, command help, ...)
  • Tested the change (unit or integration tests)
  • Amended the changelog in release.nix (see release.nix for instructions)

@curiousleo curiousleo marked this pull request as ready for review January 31, 2020 12:23
Copy link
Contributor

@grahamc grahamc left a comment

Choose a reason for hiding this comment

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

I'm going to do a quick look to see if there are methods built in to structopt to "hide" or "demote" some subcommands, but if you don't hear from me merge away :P

@curiousleo
Copy link
Collaborator Author

curiousleo commented Jan 31, 2020

I'm going to do a quick look to see if there are methods built in to structopt to "hide" or "demote" some subcommands, but if you don't hear from me merge away :P

Something like #[structopt(raw(hidden = true))] might work. I'll give it a try.

https://docs.rs/structopt/0.3.8/structopt/#raw-methods
https://docs.rs/clap/2.33.0/clap/struct.Arg.html#method.hidden
Example: TeXitoi/structopt#93

Edit: I can't get it to work.

@grahamc
Copy link
Contributor

grahamc commented Jan 31, 2020

I cracked it!

diff --git a/src/cli.rs b/src/cli.rs
index df639f6..36675ac 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -34,7 +34,7 @@ pub enum Command {
     Shell(ShellOptions),

     /// (internal) Used internally by `lorri shell`
-    #[structopt(name = "zz_start_user_shell")]
+    #[structopt(name = "zz_start_user_shell", raw(setting = "structopt::clap::AppSettings::Hidden"))]
     StartUserShell_(StartUserShellOptions_),

     /// Build project whenever an input file changes
@@ -46,7 +46,7 @@ pub enum Command {
     Daemon,

     /// (internal) Tell the lorri daemon to care about the current directory's project
-    #[structopt(name = "zz_ping")]
+    #[structopt(name = "zz_ping", raw(setting = "structopt::clap::AppSettings::Hidden"))]
     Ping_(Ping_),

     /// Upgrade lorri

maybe with this we can rename zz_ to internal_api_ or private_api_ to make callers painfully aware?

@grahamc
Copy link
Contributor

grahamc commented Jan 31, 2020

The trick was going back in time to the docs for the version of structopts we use: https://docs.rs/structopt/0.2.18/structopt/ and playing with the raw format there.

@curiousleo
Copy link
Collaborator Author

The trick was going back in time to the docs for the version of structopts we use: https://docs.rs/structopt/0.2.18/structopt/ and playing with the raw format there.

Nice

- Use "lorri" consistently instead of mixing "Lorri" and "lorri"
- Use "internal" instead of "plumbing" for internal commands
- Rename "ping_" to "internal__ping" and "start_user_shell_" to
  "internal__start_user_shell" and hide both from the autogenerated help

-------------------------------------------------------------------------------
lorri help: before the changes
-------------------------------------------------------------------------------

lorri 0.1.0
Graham Christensen <[email protected]>
Global arguments which set global program state. Most arguments will be to sub-commands.

USAGE:
    lorri [FLAGS] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Activate debug logging. Multiple occurrences are accepted for backwards compatibility, but have no
                     effect.

SUBCOMMANDS:
    daemon               Start the multi-project daemon. Replaces `lorri watch`
    direnv               Emit shell script intended to be evaluated as part of direnv's .envrc, via: `eval "$(lorri
                         direnv)"`
    help                 Prints this message or the help of the given subcommand(s)
    info                 Show information about the current Lorri project
    init                 Bootstrap files for a new setup
    ping_                (plumbing) Tell the lorri daemon to care about the current directory's project
    self-upgrade         Upgrade Lorri
    shell                Open a new shell
    start_user_shell_    (plumbing) Internal command used to launch user shell
    watch                Build `shell.nix` whenever an input file changes

-------------------------------------------------------------------------------
lorri help: after the changes
-------------------------------------------------------------------------------

lorri 0.1.0
Graham Christensen <[email protected]>
Global arguments which set global program state. Most arguments will be to sub-commands.

USAGE:
    lorri [FLAGS] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Activate debug logging. Multiple occurrences are accepted for backwards compatibility, but have no
                     effect.

SUBCOMMANDS:
    daemon          Start the multi-project daemon. Replaces `lorri watch`
    direnv          Emit shell script intended to be evaluated as part of direnv's .envrc, via: `eval "$(lorri
                    direnv)"`
    help            Prints this message or the help of the given subcommand(s)
    info            Show information about a lorri project
    init            Write bootstrap files to current directory to create a new lorri project
    self-upgrade    Upgrade lorri
    shell           Open a new project shell
    watch           Build project whenever an input file changes
@grahamc grahamc merged commit c38e0f0 into target:master Jan 31, 2020
@curiousleo curiousleo deleted the classify-subcommands branch February 3, 2020 07:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants