Skip to content

Commit

Permalink
Merge pull request #115 from cat-in-136/fix-114-cant-run-as-cargo-sub…
Browse files Browse the repository at this point in the history
…command

Fix #114 degrade bug where running as a cargo subcommand raise an error
  • Loading branch information
cat-in-136 authored Jul 10, 2024
2 parents 1511ee2 + cf66ec0 commit 8db4e24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
- name: Run binary for test purpose
shell: bash -xe {0}
run: |
cargo run --profile dev -- --profile dev
test -f target/generate-rpm/cargo-generate-rpm-*.rpm
rm -f target/generate-rpm/cargo-generate-rpm-*.rpm
cargo run --release -- generate-rpm
test -f target/generate-rpm/cargo-generate-rpm-*.rpm
rm -f target/generate-rpm/cargo-generate-rpm-*.rpm
- name: Package
run: cargo package
16 changes: 9 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ impl Cli {
T: Into<OsString> + Clone,
{
let mut args = args_fn();
let matches = if args.nth(1) == Some(OsString::from("generate-rpm")) {
if args.nth(1) == Some(OsString::from("generate-rpm")) {
let args = args_fn();
<CargoWrapper as CommandFactory>::command().get_matches_from(args)
let matches = <CargoWrapper as CommandFactory>::command().get_matches_from(args);
let CargoWrapper::GenerateRpm(arg) =
CargoWrapper::from_arg_matches_mut(&mut matches.clone())?;
Ok((arg, matches))
} else {
let args = args_fn();
<Self as CommandFactory>::command().get_matches_from(args)
};
let arg = Self::from_arg_matches_mut(&mut matches.clone())?;

Ok((arg, matches))
let matches = <Self as CommandFactory>::command().get_matches_from(args);
let arg = Self::from_arg_matches_mut(&mut matches.clone())?;
Ok((arg, matches))
}
}

pub fn get_matches_and_try_parse() -> Result<(Self, ArgMatches), clap::Error> {
Expand Down

0 comments on commit 8db4e24

Please sign in to comment.