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

did-you-mean for clap-rs #103

Merged
merged 14 commits into from
May 5, 2015
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
language: rust
rust:
- nightly
- beta
- nightly
- beta
before_script:
- git clone --depth 1 https://github.com/kbknapp/travis-cargo
- ln -s ./travis-cargo/travis-cargo.py tc
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- |
./tc cargo build &&
./tc cargo test &&
./tc cargo doc
- travis-cargo build
- travis-cargo test
- make -C clap-tests test
- travis-cargo doc
after_success:
- "./tc --only beta doc-upload"
- travis-cargo --only beta doc-upload
env:
global:
secure: JLBlgHY6OEmhJ8woewNJHmuBokTNUv7/WvLkJGV8xk0t6bXBwSU0jNloXwlH7FiQTc4TccX0PumPDD4MrMgxIAVFPmmmlQOCmdpYP4tqZJ8xo189E5zk8lKF5OyaVYCs5SMmFC3cxCsKjfwGIexNu3ck5Uhwe9jI0tqgkgM3URA=
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ keywords = ["argument", "command", "arg", "parser", "parse"]
license = "MIT"

[features]
default=[]
default=["suggestions"]
suggestions=["strsim"]

# for building with nightly and unstable features
unstable=[]

[dependencies.strsim]
version = "*"
optional = true

3 changes: 1 addition & 2 deletions clap-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ version = "0.0.1"
authors = ["Kevin K. <kbknapp@gmail.com>"]

[dependencies.clap]
git = "https://github.com/kbknapp/clap-rs"
branch = "master"
path = ".."
28 changes: 6 additions & 22 deletions clap-tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
URL:=
BRANCH:=
.PHONY: build test clean

build:
cargo update
@# It may be that this project was never built, and no Cargo.lock exists.
@# Thus it may be ignored
cargo update 2>/dev/null || :
cargo build --release

test:
cd "$(THIS_DIR)"
cp Cargo.toml cargo.bak
@read -p "Fork URL: " URL; \
sed "/^git/c\git = \"$$URL\"" cargo.bak > Cargo.toml
@read -p "Branch [master]: " BRANCH; \
$(if $(strip $(BRANCH)), \
sed -i "/^branch/c\branch = \"master\"" Cargo.toml, \
sed -i "/^branch/c\branch = \"$$BRANCH\"" Cargo.toml)
(make clean) || (make clean && false)
cd "$(THIS_DIR)"
(make build) || (make clean && false)
cd "$(THIS_DIR)"
(./run_tests.py) || (make clean && false)
mv cargo.bak Cargo.toml
make clean

$(MAKE) build || ($(MAKE) clean && false)
./run_tests.py

clean:
cd "$(THIS_DIR)"
cargo clean
29 changes: 24 additions & 5 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
--multvalsmo <one> <two> Tests mutliple values, not mult occs
-o, --option <opt>... tests options
--long-option-2 <option2> tests long options with exclusions
-O <option3> tests options with specific value sets [values: fast slow]
-O, --Option <option3> tests options with specific value sets [values: fast slow]

POSITIONAL ARGUMENTS:
positional tests positionals
Expand All @@ -35,6 +35,22 @@
help Prints this message
subcmd tests subcommands'''

_sc_dym_usage = '''Subcommand "subcm" is unknown. Did you mean "subcmd" ?
Copy link
Member

Choose a reason for hiding this comment

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

"is unknown" -> "isn't valid" to stick with previous errors

USAGE:
\tclaptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]
For more information try --help'''

_arg_dym_usage = '''The argument --optio isn't valid. Did you mean --option ?
USAGE:
\tclaptests
For more information try --help'''

_pv_dym_usage = '''"slo" isn't a valid value for '--Option <option3>'
\t[valid values: fast slow]. Did you mean "slow" ?
USAGE:
\tclaptests --Option <option3>
For more information try --help'''

_excluded = '''The argument '--flag' cannot be used with '-F'
USAGE:
\tclaptests [positional2] -F --long-option-2 <option2>
Expand Down Expand Up @@ -213,13 +229,16 @@
'mult_valsmo x2-1: ': ['{} --multvalsmo some other --multvalsmo some'.format(_bin), _mult_vals_2m1],
'mult_valsmo x1: ': ['{} --multvalsmo some other'.format(_bin), _exact],
'F2(ss),O(s),P: ': ['{} value -f -f -o some'.format(_bin), _f2op],
'arg dym: ': ['{} --optio=foo'.format(_bin), _arg_dym_usage],
'pv dym: ': ['{} --Option slo'.format(_bin), _pv_dym_usage],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, here I see a white-space error. My editor used spaces for a while, which is standard for python, whereas the file used tabs. This went unnoticed as it's apparently not an error to do that while defining a dict.
This might want to be adjusted at some point, maybe you can give it a quick-fix-commit.

'O2(ll)P: ': ['{} value --option some --option other'.format(_bin), _o2p],
'O2(l=l=)P: ': ['{} value --option=some --option=other'.format(_bin), _o2p],
'O2(ss)P: ': ['{} value -o some -o other'.format(_bin), _o2p],
'F2(s2),O(s),P: ': ['{} value -ff -o some'.format(_bin), _f2op],
'F(s),O(s),P: ': ['{} value -f -o some'.format(_bin), _fop],
'F(l),O(l),P: ': ['{} value --flag --option some'.format(_bin), _fop],
'F(l),O(l=),P: ': ['{} value --flag --option=some'.format(_bin), _fop],
'sc dym: ': ['{} subcm'.format(_bin), _sc_dym_usage],
'sc help short: ': ['{} subcmd -h'.format(_bin), _schelp],
'sc help long: ': ['{} subcmd --help'.format(_bin), _schelp],
'scF(l),O(l),P: ': ['{} subcmd value --flag --option some'.format(_bin), _scfop],
Expand All @@ -241,7 +260,7 @@

def pass_fail(name, check, good):
global failed
print(name, end='')
sys.stdout.write(name)
if check == good:
print('Pass')
return
Expand All @@ -251,9 +270,9 @@ def pass_fail(name, check, good):

def main():
for cmd, cmd_v in cmds.items():
with subprocess.Popen(cmd_v[0], shell=True, stdout=subprocess.PIPE, universal_newlines=True) as proc:
out = proc.communicate()[0].strip()
pass_fail(cmd, out, cmd_v[1])
proc = subprocess.Popen(cmd_v[0], shell=True, stdout=subprocess.PIPE, universal_newlines=True)
out = proc.communicate()[0].strip()
pass_fail(cmd, out, cmd_v[1])
if failed:
print('One or more tests failed')
return 1
Expand Down
2 changes: 1 addition & 1 deletion clap-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
Arg::from_usage("[flag2] -F 'tests flags with exclusions'").mutually_excludes("flag").requires("option2"),
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").mutually_excludes("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O [option3] 'tests options with specific value sets'").possible_values(&opt3_vals),
Arg::from_usage("-O --Option [option3] 'tests options with specific value sets'").possible_values(&opt3_vals),
Arg::from_usage("[positional3]... 'tests positionals with specific values'").possible_values(&pos3_vals),
Arg::from_usage("--multvals [multvals] 'Tests mutliple values, not mult occs'").value_names(&m_val_names),
Arg::from_usage("--multvalsmo [multvalsmo]... 'Tests mutliple values, not mult occs'").value_names(&m_val_names),
Expand Down
Loading