diff --git a/.gitignore b/.gitignore index b6d399f..848cd66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/target +target Cargo.lock .* diff --git a/.vscode/settings.json b/.vscode/settings.json index 6eb3ac9..143f49c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "rust-analyzer.imports.prefix": "crate", "trailing-spaces.includeEmptyLines": false, "editor.renderWhitespace": "all", - "git.ignoreLimitWarning": true + "git.ignoreLimitWarning": true, + "rust-analyzer.showUnlinkedFileNotification": false } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 70e0df3..3daceeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,13 @@ keywords = ["cli", "macro", "clap"] edition = "2021" exclude = [".*", "rust-toolchain", "*.toml", "justfile"] +[lib] +doctest = false + +[workspace] +members = ["impl"] + [dependencies] clap = { version = "3.0.7", features = ["derive"] } fncmd-impl = { path = "impl", version = "=1.3.0" } -once_cell = "1.9.0" - -[workspace] -members = ["impl"] \ No newline at end of file +once_cell = "1.9.0" \ No newline at end of file diff --git a/examples/example-basic/Cargo.toml b/examples/example-basic/Cargo.toml new file mode 100644 index 0000000..e2e8cea --- /dev/null +++ b/examples/example-basic/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "example-basic" +version = "0.0.0" +edition = "2021" + +[dependencies] +fncmd = { path = "../.." } + +[dev-dependencies] +trycmd = "0.14.16" + +[workspace] \ No newline at end of file diff --git a/examples/example-basic/README.md b/examples/example-basic/README.md new file mode 100644 index 0000000..cc765c4 --- /dev/null +++ b/examples/example-basic/README.md @@ -0,0 +1,43 @@ +```console +$ example-basic +? 2 +error: The following required arguments were not provided: + + +USAGE: + example-basic [OPTIONS] [NAME] + +For more information try --help + +``` + +```console +$ example-basic --help +example-basic 0.0.0 +Prints greeting message + +USAGE: + example-basic [OPTIONS] [NAME] + +ARGS: + Greeting message + Name of someone to greet + +OPTIONS: + --bang Whether to use “!” instead of “.” at the end of the message + -h, --help Print help information + -V, --version Print version information + +``` + +```console +$ example-basic Hello World +Hello, World. + +``` + +```console +$ example-basic Hello --bang +Hello! + +``` \ No newline at end of file diff --git a/examples/example-basic/src/main.rs b/examples/example-basic/src/main.rs new file mode 100644 index 0000000..efebff5 --- /dev/null +++ b/examples/example-basic/src/main.rs @@ -0,0 +1,17 @@ +/// Prints greeting message. +#[fncmd::fncmd] +fn main( + /// Greeting message. + greeting: String, + /// Name of someone to greet. + name: Option, + /// Whether to use “!” instead of “.” at the end of the message. + #[opt] + bang: bool, +) { + if let Some(name) = name { + println!("{greeting}, {name}{}", if bang { "!" } else { "." }); + } else { + println!("{greeting}{}", if bang { "!" } else { "." }); + } +} \ No newline at end of file diff --git a/examples/example-basic/tests/trycmd.rs b/examples/example-basic/tests/trycmd.rs new file mode 100644 index 0000000..6857960 --- /dev/null +++ b/examples/example-basic/tests/trycmd.rs @@ -0,0 +1,2 @@ +#[test] +fn trycmd() { trycmd::TestCases::new().case("README.md"); } \ No newline at end of file diff --git a/examples/example-subcmds/Cargo.toml b/examples/example-subcmds/Cargo.toml new file mode 100644 index 0000000..4ea24d9 --- /dev/null +++ b/examples/example-subcmds/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "example-subcmds" +version = "0.0.0" +edition = "2021" + +[dependencies] +fncmd = { path = "../.." } + +[dev-dependencies] +trycmd = "0.14.16" + +[workspace] \ No newline at end of file diff --git a/examples/example-subcmds/README.md b/examples/example-subcmds/README.md new file mode 100644 index 0000000..58666c4 --- /dev/null +++ b/examples/example-subcmds/README.md @@ -0,0 +1,52 @@ +```console +$ example-subcmds +Top-level command is called. + +``` + +```console +$ example-subcmds --help +example-subcmds 0.0.0 + +USAGE: + example-subcmds [SUBCOMMAND] + +OPTIONS: + -h, --help Print help information + -V, --version Print version information + +SUBCOMMANDS: + child + help Print this message or the help of the given subcommand(s) + +``` + +```console +$ example-subcmds child +One-level-deep subcommand is called. + +``` + +```console +$ example-subcmds child grandchild +Two-level-deep subcommand is called. + +``` + +```console +$ example-subcmds orphan +? 2 +error: Found argument 'orphan' which wasn't expected, or isn't valid in this context + +USAGE: + example-subcmds [SUBCOMMAND] + +For more information try --help + +``` + +```console +$ example-subcmds-orphan +Top-level orphan command is called. + +``` \ No newline at end of file diff --git a/examples/example-subcmds/src/bin/example-subcmds-child-grandchild.rs b/examples/example-subcmds/src/bin/example-subcmds-child-grandchild.rs new file mode 100644 index 0000000..a69afc9 --- /dev/null +++ b/examples/example-subcmds/src/bin/example-subcmds-child-grandchild.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("Two-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-subcmds/src/bin/example-subcmds-child.rs b/examples/example-subcmds/src/bin/example-subcmds-child.rs new file mode 100644 index 0000000..b4a5201 --- /dev/null +++ b/examples/example-subcmds/src/bin/example-subcmds-child.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("One-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-subcmds/src/bin/example-subcmds-orphan.rs b/examples/example-subcmds/src/bin/example-subcmds-orphan.rs new file mode 100644 index 0000000..ab3a196 --- /dev/null +++ b/examples/example-subcmds/src/bin/example-subcmds-orphan.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level orphan command is called."); +} \ No newline at end of file diff --git a/examples/example-subcmds/src/main.rs b/examples/example-subcmds/src/main.rs new file mode 100644 index 0000000..9a574b7 --- /dev/null +++ b/examples/example-subcmds/src/main.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level command is called."); +} \ No newline at end of file diff --git a/examples/example-subcmds/tests/trycmd.rs b/examples/example-subcmds/tests/trycmd.rs new file mode 100644 index 0000000..6857960 --- /dev/null +++ b/examples/example-subcmds/tests/trycmd.rs @@ -0,0 +1,2 @@ +#[test] +fn trycmd() { trycmd::TestCases::new().case("README.md"); } \ No newline at end of file diff --git a/examples/example-subcmdsflat/Cargo.toml b/examples/example-subcmdsflat/Cargo.toml new file mode 100644 index 0000000..838b6a9 --- /dev/null +++ b/examples/example-subcmdsflat/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "example-subcmdsflat" +version = "0.0.0" +edition = "2021" + +[dependencies] +fncmd = { path = "../.." } + +[dev-dependencies] +trycmd = "0.14.16" + +[workspace] \ No newline at end of file diff --git a/examples/example-subcmdsflat/README.md b/examples/example-subcmdsflat/README.md new file mode 100644 index 0000000..bab9675 --- /dev/null +++ b/examples/example-subcmdsflat/README.md @@ -0,0 +1,52 @@ +```console +$ example-subcmdsflat +Top-level command is called. + +``` + +```console +$ example-subcmdsflat --help +example-subcmdsflat 0.0.0 + +USAGE: + example-subcmdsflat [SUBCOMMAND] + +OPTIONS: + -h, --help Print help information + -V, --version Print version information + +SUBCOMMANDS: + child + help Print this message or the help of the given subcommand(s) + +``` + +```console +$ example-subcmdsflat child +One-level-deep subcommand is called. + +``` + +```console +$ example-subcmdsflat child grandchild +Two-level-deep subcommand is called. + +``` + +```console +$ example-subcmdsflat orphan +? 2 +error: Found argument 'orphan' which wasn't expected, or isn't valid in this context + +USAGE: + example-subcmdsflat [SUBCOMMAND] + +For more information try --help + +``` + +```console +$ example-subcmdsflat-orphan +Top-level orphan command is called. + +``` \ No newline at end of file diff --git a/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child-grandchild.rs b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child-grandchild.rs new file mode 100644 index 0000000..a69afc9 --- /dev/null +++ b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child-grandchild.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("Two-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child.rs b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child.rs new file mode 100644 index 0000000..b4a5201 --- /dev/null +++ b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-child.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("One-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-subcmdsflat/src/bin/example-subcmdsflat-orphan.rs b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-orphan.rs new file mode 100644 index 0000000..ab3a196 --- /dev/null +++ b/examples/example-subcmdsflat/src/bin/example-subcmdsflat-orphan.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level orphan command is called."); +} \ No newline at end of file diff --git a/examples/example-subcmdsflat/src/bin/example-subcmdsflat.rs b/examples/example-subcmdsflat/src/bin/example-subcmdsflat.rs new file mode 100644 index 0000000..9a574b7 --- /dev/null +++ b/examples/example-subcmdsflat/src/bin/example-subcmdsflat.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level command is called."); +} \ No newline at end of file diff --git a/examples/example-subcmdsflat/tests/trycmd.rs b/examples/example-subcmdsflat/tests/trycmd.rs new file mode 100644 index 0000000..6857960 --- /dev/null +++ b/examples/example-subcmdsflat/tests/trycmd.rs @@ -0,0 +1,2 @@ +#[test] +fn trycmd() { trycmd::TestCases::new().case("README.md"); } \ No newline at end of file diff --git a/examples/example-workspace/Cargo.toml b/examples/example-workspace/Cargo.toml new file mode 100644 index 0000000..cc43197 --- /dev/null +++ b/examples/example-workspace/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = ["crates/*"] + +[workspace.package] +version = "0.0.0" +edition = "2021" \ No newline at end of file diff --git a/examples/example-workspace/crates/bar/Cargo.toml b/examples/example-workspace/crates/bar/Cargo.toml new file mode 100644 index 0000000..2fb9953 --- /dev/null +++ b/examples/example-workspace/crates/bar/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "example-workspace-bar" +version.workspace = true +edition.workspace = true + +[dependencies] +fncmd = { path = "../../../.." } + +[dev-dependencies] +trycmd = "0.14.16" \ No newline at end of file diff --git a/examples/example-workspace/crates/bar/README.md b/examples/example-workspace/crates/bar/README.md new file mode 100644 index 0000000..c9d5e96 --- /dev/null +++ b/examples/example-workspace/crates/bar/README.md @@ -0,0 +1,11 @@ +```console +$ example-workspace-bar +Top-level command is called. + +``` + +```console +$ example-workspace-bar child +One-level-deep subcommand is called. + +``` \ No newline at end of file diff --git a/examples/example-workspace/crates/bar/src/bin/example-workspace-bar-child.rs b/examples/example-workspace/crates/bar/src/bin/example-workspace-bar-child.rs new file mode 100644 index 0000000..b4a5201 --- /dev/null +++ b/examples/example-workspace/crates/bar/src/bin/example-workspace-bar-child.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("One-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-workspace/crates/bar/src/main.rs b/examples/example-workspace/crates/bar/src/main.rs new file mode 100644 index 0000000..9a574b7 --- /dev/null +++ b/examples/example-workspace/crates/bar/src/main.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level command is called."); +} \ No newline at end of file diff --git a/examples/example-workspace/crates/bar/tests/trycmd.rs b/examples/example-workspace/crates/bar/tests/trycmd.rs new file mode 100644 index 0000000..6857960 --- /dev/null +++ b/examples/example-workspace/crates/bar/tests/trycmd.rs @@ -0,0 +1,2 @@ +#[test] +fn trycmd() { trycmd::TestCases::new().case("README.md"); } \ No newline at end of file diff --git a/examples/example-workspace/crates/foo/Cargo.toml b/examples/example-workspace/crates/foo/Cargo.toml new file mode 100644 index 0000000..3209446 --- /dev/null +++ b/examples/example-workspace/crates/foo/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "example-workspace-foo" +version.workspace = true +edition.workspace = true + +[dependencies] +fncmd = { path = "../../../.." } + +[dev-dependencies] +trycmd = "0.14.16" \ No newline at end of file diff --git a/examples/example-workspace/crates/foo/README.md b/examples/example-workspace/crates/foo/README.md new file mode 100644 index 0000000..d25a515 --- /dev/null +++ b/examples/example-workspace/crates/foo/README.md @@ -0,0 +1,11 @@ +```console +$ example-workspace-foo +Top-level command is called. + +``` + +```console +$ example-workspace-foo child +One-level-deep subcommand is called. + +``` \ No newline at end of file diff --git a/examples/example-workspace/crates/foo/src/bin/example-workspace-foo-child.rs b/examples/example-workspace/crates/foo/src/bin/example-workspace-foo-child.rs new file mode 100644 index 0000000..b4a5201 --- /dev/null +++ b/examples/example-workspace/crates/foo/src/bin/example-workspace-foo-child.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +pub fn main() { + println!("One-level-deep subcommand is called."); +} \ No newline at end of file diff --git a/examples/example-workspace/crates/foo/src/main.rs b/examples/example-workspace/crates/foo/src/main.rs new file mode 100644 index 0000000..9a574b7 --- /dev/null +++ b/examples/example-workspace/crates/foo/src/main.rs @@ -0,0 +1,4 @@ +#[fncmd::fncmd] +fn main() { + println!("Top-level command is called."); +} \ No newline at end of file diff --git a/examples/example-workspace/crates/foo/tests/trycmd.rs b/examples/example-workspace/crates/foo/tests/trycmd.rs new file mode 100644 index 0000000..6857960 --- /dev/null +++ b/examples/example-workspace/crates/foo/tests/trycmd.rs @@ -0,0 +1,2 @@ +#[test] +fn trycmd() { trycmd::TestCases::new().case("README.md"); } \ No newline at end of file diff --git a/impl/Cargo.toml b/impl/Cargo.toml index bd3dc2f..e95ce65 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" exclude = ["release.toml"] [lib] +doctest = false proc-macro = true [dependencies] diff --git a/justfile b/justfile index ab81c56..6df43ec 100644 --- a/justfile +++ b/justfile @@ -5,6 +5,11 @@ setup: chmod +x .githooks/* git config --local core.hooksPath .githooks +test *ARGS: + for project in `ls examples`; do \ + RUST_BACKTRACE=1 cargo test --manifest-path examples/$project/Cargo.toml --workspace {{ARGS}} -- --nocapture; \ + done + bump *ARGS: cargo release --workspace --sign-commit --no-tag --no-push --no-publish \ $(convco version --bump) {{ARGS}}