Code Monkey home page Code Monkey logo

arg.rs's People

Contributors

doumanash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

arg.rs's Issues

Clarify what "No dependencies" means

Hello,

I was excited to see an arg parser with "No dependencies", and confused to see that it does indeed have 6 dependencies as shown by cargo tree:

prj v0.1.0 (/home/sam/prj)
└── arg v0.4.1
    └── arg-derive v0.4.1 (proc-macro)
        ├── quote v1.0.23
        │   └── proc-macro2 v1.0.51
        │       └── unicode-ident v1.0.6
        ├── syn v1.0.109
        │   ├── proc-macro2 v1.0.51 (*)
        │   ├── quote v1.0.23 (*)
        │   └── unicode-ident v1.0.6
        └── tabwriter v1.2.1
            └── unicode-width v0.1.10

I suspect these maybe compile time dependencies, and the claim should actually be "No runtime dependencies" - is it reasonable to update the README with that ?

Sorry for the pedantry BTW, there are situations where all external dependencies need to be accounted for, so I am sensitive to this distinction :)

Error when setting the default_value of an option that is a string

The program will exit with an error if a default_value is set for -n:

╭ emma@noire-carnation
│ ~/s/T/yac/coreutils
╰─[tail]# ./tail -n -12
./tail: Unknown flag 'n' is provided

from src/tail.rs:

#[derive(Args, Debug)]
struct Arguments {
  _argv0: String,

  #[arg(short = "c")]
  c: Option<String>,

  #[arg(short = "f")]
  f: bool,

  #[arg(short = "n", default_value: String = "-10")]
  n: String,

  #[arg(default_value = vec!["-"])]
  paths: Vec<String>,
}

fn main() {
  let (args, argv) = match get_args::<Arguments>() {
    Ok((args, argv)) => (args, argv),
    Err(err) => {
      eprintln!("{}", err);
      exit(EX_USAGE);
    },
  };

  let head = match Path::new(&argv[0]).file_name() {
    Some(val) => val.eq(OsStr::new("head")),
    None => false,
  };

  if head && (args.c.is_some() || args.f) {
    eprintln!("Usage: {} [options...] [file]", argv[0]);
    exit(EX_USAGE);
  }

  let count: isize;
  
  let opt = match args.c.is_some() {
    true => args.c.unwrap(),
    false => args.n,
  };

  match signs(&argv, opt) {
    Ok(RealSignedInt::Unsigned(val)) => {
      let out = val as isize;
      count = -out;
    },
    Ok(RealSignedInt::Signed(val)) => count = val,
    Err(err) => {
      eprintln!("{}", err);
      exit(EX_USAGE);
    },
  };
}

relevant function:

pub fn get_args<T: arg::Args>() -> Result<(T, Vec<String>), String> {
  let argv = args().collect::<Vec<String>>();

  match T::from_args(argv
    .iter()
    .map(String::as_str)
    .collect::<Vec<&str>>()
  ) {
    Ok(args) => Ok((args, argv)),
    Err(ParseKind::Top(kind)) => {
      Err(format!("{}: {}", argv[0], kind))
    },
    Err(ParseKind::Sub(command, kind)) => {
      Err(format!("Usage: {} {} [options...]", argv[0], command))
    }
  }
}

Cannot parse "-"

When passing "-" to a command to give it stdin, the command returns:
'target/x86_64-unknown-linux-gnu…' terminated by signal SIGILL (Illegal instruction)

How to use `from_args` and `std::env::args()`?

let mut args = std::env::args();
let _program_name = args.next().unwrap();
let args = ProgramArgs::from_args(args);
//let args = ProgramArgs::from_args(args.map(|arg| arg.as_str()));

Feature request: subcommands

It would be cool to have support for non-opt subcommands that don't have dashes before them. Would this be possible/in scope for this crate?

#[derive(Args, Debug)]
struct Arguments {
  argv0: String,

  #[arg(subcommand)]
  get: Vec<String>,
}

and then argv0 get string1 string2 string3 gives you:

Arguments.argv0 == "argv0";
Arguments.get == [ "string1", "string2", "string3" ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.