Skip to content

Commit

Permalink
Remove version option from subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jan 29, 2022
1 parent 1bd3c89 commit 55b0f04
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 66 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ goldie = "0.1.0"
pest = "2.1.3"
pest_derive = "2.1.0"
pretty_assertions = "1.0.0"
serde_json = "1.0.78"
tempfile = "3.3.0"

[workspace]
Expand Down
16 changes: 8 additions & 8 deletions completions/sheldon.bash
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ _sheldon() {
return 0
;;
sheldon__add)
opts="-h -V --git --gist --github --remote --local --proto --branch --rev --tag --dir --use --apply --help --version <NAME>"
opts="-h --git --gist --github --remote --local --proto --branch --rev --tag --dir --use --apply --help <NAME>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -151,7 +151,7 @@ _sheldon() {
return 0
;;
sheldon__completions)
opts="-h -V --shell --help --version"
opts="-h --shell --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -169,7 +169,7 @@ _sheldon() {
return 0
;;
sheldon__edit)
opts="-h -V --help --version"
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -183,7 +183,7 @@ _sheldon() {
return 0
;;
sheldon__init)
opts="-h -V --shell --help --version"
opts="-h --shell --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -201,7 +201,7 @@ _sheldon() {
return 0
;;
sheldon__lock)
opts="-h -V --update --reinstall --help --version"
opts="-h --update --reinstall --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -215,7 +215,7 @@ _sheldon() {
return 0
;;
sheldon__remove)
opts="-h -V --help --version <NAME>"
opts="-h --help <NAME>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -229,7 +229,7 @@ _sheldon() {
return 0
;;
sheldon__source)
opts="-h -V --relock --update --reinstall --help --version"
opts="-h --relock --update --reinstall --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -243,7 +243,7 @@ _sheldon() {
return 0
;;
sheldon__version)
opts="-h -V --help --version"
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
16 changes: 0 additions & 16 deletions completions/sheldon.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ _arguments "${_arguments_options[@]}" \
'--shell=[The type of shell, accepted values are: bash, zsh]:SHELL: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
(add)
Expand All @@ -65,25 +63,19 @@ _arguments "${_arguments_options[@]}" \
'*--apply=[Templates to apply to this plugin]:TEMPLATE: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
':name -- A unique name for this plugin:' \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
':name -- A unique name for this plugin:' \
&& ret=0
;;
Expand All @@ -93,8 +85,6 @@ _arguments "${_arguments_options[@]}" \
'(--update)--reinstall[Reinstall all plugin sources]' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
(source)
Expand All @@ -104,25 +94,19 @@ _arguments "${_arguments_options[@]}" \
'(--update)--reinstall[Reinstall all plugin sources (implies --relock)]' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" \
'--shell=[The type of shell, accepted values are: bash, zsh]:SHELL: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
(version)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
&& ret=0
;;
esac
Expand Down
33 changes: 11 additions & 22 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ enum RawCommand {
global_setting = AppSettings::DeriveDisplayOrder,
global_setting = AppSettings::DisableHelpSubcommand,
global_setting = AppSettings::DisableColoredHelp,
global_setting = AppSettings::PropagateVersion,
setting = AppSettings::SubcommandRequired,
)]
struct RawOpt {
Expand Down Expand Up @@ -503,35 +502,25 @@ mod tests {

use std::iter;

use clap::{crate_authors, crate_description, crate_name};
use pretty_assertions::assert_eq;
use serde_json as json;
use serde_json::json;

fn setup() {
for (k, _) in env::vars() {
if k.starts_with(&format!("{}_", crate_name!().to_uppercase())) || k.starts_with("XDG_")
if k.starts_with(&format!("{}_", build::CRATE_NAME.to_uppercase()))
|| k.starts_with("XDG_")
{
env::remove_var(k);
}
}
}

fn ctx() -> json::Value {
json!({
"name": build::CRATE_NAME,
"version": build::CRATE_RELEASE,
"authors": crate_authors!(),
"description": crate_description!(),
})
}

fn raw_opt(args: &[&str]) -> RawOpt {
RawOpt::try_parse_from(iter::once(crate_name!()).chain(args.iter().copied())).unwrap()
RawOpt::try_parse_from(iter::once(build::CRATE_NAME).chain(args.iter().copied())).unwrap()
}

fn raw_opt_err(args: &[&str]) -> clap::Error {
RawOpt::try_parse_from(iter::once(crate_name!()).chain(args.iter().copied())).unwrap_err()
RawOpt::try_parse_from(iter::once(build::CRATE_NAME).chain(args.iter().copied()))
.unwrap_err()
}

#[test]
Expand Down Expand Up @@ -561,7 +550,7 @@ mod tests {
setup();
for opt in &["-h", "--help"] {
let err = raw_opt_err(&[opt]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::DisplayHelp);
}
}
Expand Down Expand Up @@ -638,15 +627,15 @@ mod tests {
fn raw_opt_subcommand_required() {
setup();
let err = raw_opt_err(&[]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::MissingSubcommand);
}

#[test]
fn raw_opt_init_help() {
setup();
let err = raw_opt_err(&["init", "--help"]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::DisplayHelp);
}

Expand All @@ -663,7 +652,7 @@ mod tests {
fn raw_opt_add_help() {
setup();
let err = raw_opt_err(&["add", "--help"]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::DisplayHelp);
}

Expand Down Expand Up @@ -977,7 +966,7 @@ mod tests {
fn raw_opt_lock_help() {
setup();
let err = raw_opt_err(&["lock", "--help"]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::DisplayHelp);
}

Expand All @@ -994,7 +983,7 @@ mod tests {
fn raw_opt_source_help() {
setup();
let err = raw_opt_err(&["source", "--help"]);
goldie::assert_template!(ctx(), err.to_string());
goldie::assert!(err.to_string());
assert_eq!(err.kind, clap::ErrorKind::DisplayHelp);
}

Expand Down
5 changes: 2 additions & 3 deletions src/testdata/cli/raw_opt_add_help.golden
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{name}-add {version}
sheldon-add
Add a new plugin to the config file

USAGE:
{name} add [OPTIONS] <--git <URL>|--gist <ID>|--github <REPO>|--remote <URL>|--local <DIR>> <NAME>
sheldon add [OPTIONS] <--git <URL>|--gist <ID>|--github <REPO>|--remote <URL>|--local <DIR>> <NAME>

ARGS:
<NAME> A unique name for this plugin
Expand All @@ -21,4 +21,3 @@ OPTIONS:
--use <MATCH>... Which files to use in this plugin
--apply <TEMPLATE>... Templates to apply to this plugin
-h, --help Print help information
-V, --version Print version information
8 changes: 4 additions & 4 deletions src/testdata/cli/raw_opt_help.golden
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{name} {version}
{authors}
{description}
sheldon 0.6.5
Ross MacArthur <[email protected]>
Fast, configurable, shell plugin manager.

USAGE:
{name} [OPTIONS] <SUBCOMMAND>
sheldon [OPTIONS] <SUBCOMMAND>

OPTIONS:
-q, --quiet Suppress any informational output
Expand Down
5 changes: 2 additions & 3 deletions src/testdata/cli/raw_opt_init_help.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{name}-init {version}
sheldon-init
Initialize a new config file

USAGE:
{name} init [OPTIONS]
sheldon init [OPTIONS]

OPTIONS:
--shell <SHELL> The type of shell, accepted values are: bash, zsh
-h, --help Print help information
-V, --version Print version information
5 changes: 2 additions & 3 deletions src/testdata/cli/raw_opt_lock_help.golden
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{name}-lock {version}
sheldon-lock
Install the plugins sources and generate the lock file

USAGE:
{name} lock [OPTIONS]
sheldon lock [OPTIONS]

OPTIONS:
--update Update all plugin sources
--reinstall Reinstall all plugin sources
-h, --help Print help information
-V, --version Print version information
5 changes: 2 additions & 3 deletions src/testdata/cli/raw_opt_source_help.golden
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{name}-source {version}
sheldon-source
Generate and print out the script

USAGE:
{name} source [OPTIONS]
sheldon source [OPTIONS]

OPTIONS:
--relock Regenerate the lock file
--update Update all plugin sources (implies --relock)
--reinstall Reinstall all plugin sources (implies --relock)
-h, --help Print help information
-V, --version Print version information
4 changes: 2 additions & 2 deletions src/testdata/cli/raw_opt_subcommand_required.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error: '{name}' requires a subcommand, but one was not provided
error: 'sheldon' requires a subcommand, but one was not provided

USAGE:
{name} [OPTIONS] <SUBCOMMAND>
sheldon [OPTIONS] <SUBCOMMAND>

For more information try --help

0 comments on commit 55b0f04

Please sign in to comment.