A crate implementing POSIX/GNU-style --flags.

Related tags

System tools pflag
Overview

Documentation

pflag

pflag is a port of the spf13's popular fork of the Go package by the same name.

Usage

("num").unwrap(), 1); assert_eq!(*flags.value_of::("str").unwrap(), "world"); assert_eq!(flags.value_of::>("addrs").unwrap().len(), 3); // Any non-flag args i.e. positional args can be retrieved by... let args = flags.args(); assert_eq!(args.len(), 1); assert_eq!(args[0], "subcommand"); ">
use pflag::{FlagSet, Slice};
use std::net::{IpAddr, Ipv4Addr};

let mut flags = FlagSet::new("name");

// Use higher level methods over add_flag directly.
flags.int8("num", 0, "a flag for a number");
flags.string_p("str", 's', String::from("default value"), "a flag for a String and has a shorthand");
flags.ip_addr_slice(
    "addrs",
    Slice::from([IpAddr::V4(Ipv4Addr::new(0,0,0,0)), IpAddr::V4(Ipv4Addr::new(127,0,0,1))]),
    "a multi-valued flag",
);

let args = "--num=1 -s world --addrs 192.168.1.1,192.168.0.1 --addrs=127.0.0.1 subcommand";
if let Err(err) = flags.parse(args.split(' ')) {
    panic!(err);
}

// Retrieving value is very easy with the value_of method.
assert_eq!(*flags.value_of::<i8>("num").unwrap(), 1);
assert_eq!(*flags.value_of::<String>("str").unwrap(), "world");
assert_eq!(flags.value_of::>("addrs").unwrap().len(), 3);

// Any non-flag args i.e. positional args can be retrieved by...
let args = flags.args();
assert_eq!(args.len(), 1);
assert_eq!(args[0], "subcommand");
You might also like...
Extract documentation for the feature flags from comments in Cargo.toml

Document your crate's feature flags This crate provides a macro that extracts documentation comments from Cargo.toml To use this crate, add #![doc = d

Toggle parallelism with feature flags!

maybe_parallel_iterator Write your code once. Then toggle between sequential and parallel iterators with a feature flag! let a: Veci32 = (0..100).co

A rust interval arithmetic library which provides flags that detect domain errors.

intervals-good A Rust interval arithmetic library which provides flags that detect domain errors, supports more functions than any other interval arit

Find potential unused enabled feature flags and prune them.
Find potential unused enabled feature flags and prune them.

Potential unused, enabled feature flag finder and pruner. This cargo tool allows you to find and prune enabled, but, potentially unused feature flags

Pulls the C/C++ library linking flags from Conan dependencies

conan2-rs Introduction conan2-rs is a Cargo build script wrapper of the Conan C/C++ package manager (version 2.0 only). It automatically pulls the C/C

A crate built on top of `axum-sessions`, implementing the CSRF Synchronizer Token Pattern

Axum Synchronizer Token Pattern CSRF prevention This crate provides a Cross-Site Request Forgery protection layer and middleware for use with the axum

Rust crate implementing short & stable ids based on timestamps

Lexicoid Short & stable IDs based on timestamps. Heavily inspired by Short, friendly base32 slugs from timestamps by @brandur. Install Install with ca

Cross-platform Rust rewrite of the GNU coreutils

uutils coreutils uutils is an attempt at writing universal (as in cross-platform) CLI utilities in Rust. This repository is intended to aggregate GNU

On the fly syntax checking for GNU Emacs
On the fly syntax checking for GNU Emacs

https://www.flycheck.org Modern on-the-fly syntax checking extension for GNU Emacs. Try it! For a more gentle introduction read the Installation instr

A toy re-implementation of GNU Grep by Rust.

Mini Grep Mini Grep is a simple rust re-implementation of GNU Grep, which means it could just implement limited functions, such as searching specific

DWARF packaging utility, written in Rust, supporting GNU extension and DWARF 5 package formats.

thorin thorin is an DWARF packaging utility for creating DWARF packages (*.dwp files) out of input DWARF objects (*.dwo files; or *.o files with .dwo

Cross-platform Rust rewrite of the GNU coreutils
Cross-platform Rust rewrite of the GNU coreutils

Cross-platform Rust rewrite of the GNU coreutils

DWARF packaging utility, written in Rust, supporting GNU extension and DWARF 5 package formats.

thorin thorin is an DWARF packaging utility for creating DWARF packages (*.dwp files) out of input DWARF objects (*.dwo files; or *.o files with .dwo

Gnu-copypasta-maker - You'd just wanna interject for a moment!

GNU Copypasta Maker To compile, use make. To install, use sudo make install or if you are root make install To uninstall, use sudo make uninstall or i

little brother of gnu-copypasta-maker To compile, use make.

UWU Maker little brother of gnu-copypasta-maker To compile, use make. To install, use sudo make install or if you are root make install To uninstall,

A tongue-in-cheek GUI that provides similar functionality to GNU cat
A tongue-in-cheek GUI that provides similar functionality to GNU cat

catboy a tongue-in-cheek GUI that provides similar functionality to GNU cat information: Attribute Value Development Status: Active Neglect Price: I h

A collection of semi-useful tools made for GNU/Linux

DECTOOLS A collection of semi-useful tools made for GNU/Linux. Some may work on macOS, though functionality isn't a priority. Depenencies: python, bas

A GSL (the GNU Scientific Library) binding for Rust

rust-GSL A Rust binding for the GSL library (the GNU Scientific Library). The minimum support Rust version is 1.54. Installation This binding requires

Apple dynamic HEIF wallpapers on GNU/Linux.
Apple dynamic HEIF wallpapers on GNU/Linux.

timewall Apple dynamic HEIF wallpapers on GNU/Linux. Features: Support for original HEIF/HEIC dynamic wallpaper files used in MacOS. Support for all s

Comments
  • bug: single dash not recognized as pos arg

    bug: single dash not recognized as pos arg

    A single dash, -, followed by a space should be recognized as a positional arg. It is traditionally used to signify input coming from stdin instead of command line args.

    bug 
    opened by Zaba505 0
Releases(v0.6.2)
Owner
null
A toy re-implementation of GNU Grep by Rust.

Mini Grep Mini Grep is a simple rust re-implementation of GNU Grep, which means it could just implement limited functions, such as searching specific

PeterWrght 1 Jul 15, 2022
A small linktree style app using Yew.

Links This is a small website built using Yew. It uses trunk to run locally, and build for deployment. I wanted to explore this library and see how it

Josh Finnie 4 Aug 29, 2022
A lib crate for gathering system info such as cpu, distro, environment, kernel, etc in Rust.

nixinfo A lib crate for gathering system info such as cpu, distro, environment, kernel, etc in Rust. To use: nixinfo = "0.2.8" in your Cargo.toml. Cur

ValleyKnight 37 Nov 26, 2022
A theming crate for fltk-rs

fltk-theme A theming crate for fltk-rs, based on work by Remy Oukaour and Greg Ercolano, and schemes developed by the NTK GUI library. Usage [dependen

null 53 Dec 27, 2022
Document your crate's feature flags

Document your crate's feature flags This crate provides a macro that extracts documentation comments from Cargo.toml To use this crate, add #![doc = d

SixtyFPS 83 Dec 15, 2022
An OS kernel written in rust. Non POSIX

"Tifflin" Experimental Kernel (and eventually Operating System) This is an experiment in writing an OS Kernel in rust (http://rust-lang.org). Mostly t

John Hodge (Mutabah) 618 Jan 8, 2023
Xrs is a POSIX-subset operating system kernel written in Rust.

XRS-OS ( ?? WIP) Xrs is a POSIX-subset operating system kernel written in Rust. Current project team members 0x5459 core developer (he/him) 0x5457 cor

null 7 Nov 16, 2022
A command-line shell like fish, but POSIX compatible.

A command-line shell like fish, but POSIX compatible.

Seiya Nuta 813 Dec 29, 2022
A POSIX select I/O Multiplexing Rust library.

A POSIX select I/O Multiplexing Rust library.

b23r0 4 Jul 6, 2022
Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

nvm.sh 63.8k Jan 7, 2023