Git Product home page Git Product logo

argi's Introduction

argi

Argument parsing for the future ๐Ÿš€

Features

  • Intuative macro approach
  • Speedy compile times
  • Zero dependencies, tiny binary bloat
  • Rich auto-help generation with modern styling

Quickstart

First, add this to your Cargo.toml file:

[dependencies]
argi = "0.1.0-beta.5"

And then you can create a simple application:

// TODO

When ran, you should see the following help message:

TODO

You can find this and many more demo projects inside of the useful examples/ directory!

Comparisons

The below sections contain comparisons to similar, competing libraries. Please note that we try to be as unbiased as possible but there is sadly a natural COI here.

  • Versus clap

    TODO

  • Versus argh

    TODO

Licensing

This project is dual-licensed under both the MIT and Apache, so feel free to use either at your discretion.

argi's People

Contributors

owez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

iq-scm

argi's Issues

Optional commands shouldn't take precident over subcommands

Optional arguments are currently gobbling up valid subcommands. For example, when a user tries ab cd and cd is a command but ab has optional data, optional takes precedence and gobbles when it shouldn't. This issue was taken from these two old and quite ambiguous comments:

// TODO: optional is gobbling others, need to maybe peek and check
// TODO: rewrite data

Hyphenated arguments like `--long-opt` don't parse in macros

If I try to use an argument with a hypen in it, I get a compile error like:

error[E0609]: no field `args` on type `&argi::Argument<'_>`
  --> bin/main.rs:44:11
   |
44 |     match data!(bool, ctx => --include-methods) {
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown field

Is this supported? Could it be? Perhaps by specifying the arg in quotes/string...

Clean up `cli!()` and `cli_below!()` macros

They currently have a mixture of brute-force matching and TT munching, where we should really only be using TT munching under the current design which is superior. Another speedup would be moving away from the non-functionised part in cli_below!() which is as so:

// recursion-only
($cmd:expr; $($($left:literal),* $(,)? $(:)? { $($tail:tt)* }),* $(,)?) => {
    // etc
}

Doing this would most likely drastically help compiletimes for more complex cli apps, as well as allow easier maintenance.

Manpage auto-generation

Manual pages should also be a primary post-release feature, perhaps a little further down the line then #5 as they are still frequently used in modern times. It should not have any message truncation (#2) etc and should be in the man-page format.

Not sure about if this should be a feature gate because the parsing complexity may be quite large due to specific manpage formatting requirements (i.e. the troff format).

"Did you mean .." typo correction

Important post-release feature, having a typo correction algorithm implemented helps a lot in my opinion and its a feature I like to see on other argparsers but that's missing from this.

Argument searching

Now that most everything else is finished, argument searching (for both generally and for if only used == true) is a must

Common arg/command

There are many reused sections to both commands and args, see:

pub struct Argument<'a> {
    /// Calls which can be made which instigate this argument
    pub instigators: &'a [&'a str],
    // the following values have been flattened into this and argument and function the same, this is for end user ease of use as the cost of us
    /// Help message, if added, for this argument
    pub help: Help<'a>,
    /// The type of data this argument parses, if any
    pub parses: Option<&'a str>,
    /// Indicates if a user has invoked this argument at any point
    pub used: bool,
    /// User-implemented closure which is ran at parse-time, if added
    pub run: Option<fn(&Self, Option<String>)>,
    /// Raw data found from parsing
    pub data: Option<String>,
}

versus the command:

pub struct Command<'a> {
    pub name: &'a str,
    pub args: Vec<Argument<'a>>,
    pub subcmds: Vec<Command<'a>>,
    // the following values have been flattened into this and argument and function the same, this is for end user ease of use as the cost of us
    /// Help message, if added, for this argument
    pub help: Help<'a>,
    /// The type of data this command parses, if any
    pub parses: Option<&'a str>,
    /// Indicates if a user has invoked this command at any point
    pub used: bool,
    /// User-implemented closure which is ran at parse-time, if added
    pub run: Option<fn(&Self, Option<String>)>,
    /// Raw data found from parsing
    pub data: Option<String>,
}

Only 4 items in total are different (1 for arguments, 3 for commands) and the rest are flattened badly for better user experience, which is now null and void due to the inclusion of the data() command method.

Example in README is defective

Need to change the cli! curly braces to parens (or otherwise surround the cli! invocation with parens to make an expression) for the README example to compile.

Once compiled, the README example produces no output when run.

Does it handle non-UTF8 filenames on Unix-like systems?

Can it be used, for example, to pass entire command line array to a subprocess unmodified without restrictions, like xargs?
Does it start from std::env::args (simpler, but makes this task impossible) or from std::env::args_os (proper way, but tricky)?

Optional data

The macro should allow [value?] for optional data along with optional: true for long-form inputting. Should then not give data required errors or no commands inputted

Replace `HelpType` with just an `Option<&str>` type

Simpler and less prone to weirdness caused by a user potentially submitting "path" instead of path etc; simplifying checks and the library as a whole. The None still acts as a barrier so nothing really changes on that front

Documentation run

When this project is further in development, all public items should be properly and fully documented with high-level examples for all. As for now however, they are purposefully more undocumented then private items.

Improved `.data()` fetching

A further extension to .data() fetching should be multiple parts in data like so:

ctx.data("subcmd --argument")

Instead of the current system which is:

ctx.get_cmd("subcmd").data("--argument")

Originally posted by @Owez in #10 (comment)

More examples

Before 0.1.0 release, there should be more demos and a restructured examples dir

Truncate help messages

https://github.com/Owez/clonk/blob/15e8676fe218f63a4f6ca36f4f33300161f9c2d3/src/lib.rs#L185

Currently, we allow infinate length help messages, which are good for command-specific autohelp, e.g. ./program my_command --help, but may not format properly on the overview ./program --help where my_command may be a sub-command. To fix this I propose two changes:

  1. If a help message has a newline, only show the first line in the overview message and the full help in the command-specific help
  2. Truncate using .. to either fit terminal length or more realistically 80 characters if the total length of the line is >80

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.