#user #quickly #parser #acts #control #path #write

fpr-cli

A library that allows one to write cli tools quickly

18 releases

0.2.6 Nov 14, 2024
0.2.5 Nov 14, 2024
0.1.11 Oct 28, 2024
0.1.8 Sep 24, 2024
0.1.6 Jun 19, 2024

#457 in Configuration

Download history 124/week @ 2024-08-31 15/week @ 2024-09-07 24/week @ 2024-09-14 188/week @ 2024-09-21 30/week @ 2024-09-28 7/week @ 2024-10-05 6/week @ 2024-10-12 140/week @ 2024-10-19 230/week @ 2024-10-26 285/week @ 2024-11-02 456/week @ 2024-11-09 57/week @ 2024-11-16

1,166 downloads per month
Used in fpr-sh

Apache-2.0

34KB
974 lines

What is it?

A tool to help you build CLI programs quickly.

Motivating Example

#[derive(Acts)]
#[acts(desc = "salt")]
#[allow(dead_code)]
pub struct Main(
    Printscreen,
    Copy,
    Paste,
    Headset,
    # ...
);

#[derive(Args)]
#[args(desc = "Take a screenshot.")]
struct Printscreen {
    # Static defaults
    #[arg(desc = "The saved image.", s = ("/tmp/image.png"))]
    pub path: String,
}
impl Run<C> for Printscreen {
    type R = ();
    fn run(_: &C, a: Self) -> Result<Self::R, String> {
        sh::printscreen(&a.path)
    }
}

#[derive(Args)]
#[args(desc = "Copy to clipboard.")]
struct Copy {}
impl Run<C> for Copy {
    type R = ();
    fn run(_: &C, _: Self) -> Result<Self::R, String> {
        sh::copy()
    }
}

#[derive(Args)]
#[args(desc = "Paste from clipboard.")]
struct Paste {
    #[arg(desc = "Path to paste the file to.")]
    pub path: Option<String>
}
impl Run<C> for Paste {
    type R = String;
    fn run(_: &C, a: Self) -> Result<Self::R, String> {
        let r = sh::paste()?;
        println!("{r}");
        if let Some(p) => a.path {
            # ...
        }
        Ok(r)
    }
}

# Submenus
#[derive(Acts)]
#[acts(desc = "Headset controls.")]
#[allow(dead_code)]
pub struct Headset(Con, Dis);

#[derive(Args)]
#[args(desc = "Disconnect.")]
struct Dis {
    # Dynamic defaults
    #[arg(desc = "Headphone identifier.", d = |c| c.get_headphone())]
    pub path: String,
}
impl Run<C> for Dis {
    type R = ();
    fn run(c: &C, _: Self) -> Result<Self::R, String> {
        # ...
    }
}
$ salt
Expected an act.
? Choose an action.
> printscreen   Take a screenshot.
  headset       Headset controls.
  copy          Copy to clipboard.
  paste         Paste from clipboard.
[↑↓ to move, enter to select, type to filter]
# Submenus
$ salt
Expected an act.
> Choose an action. headset       Headset controls.
Expected an act.
? Choose an action.
  con Connect.
> dis Disconnect.
[↑↓ to move, enter to select, type to filter]
Operation was interrupted by the user
# Print help when needed.
$ salt gopro
Failed to parse opts.
Error parsing option '--dev.'
Required.
Usage: salt gopro <opts...>
Opts:
--dev Req<String> The device name for the GoPro. ex) /dev/sde1

Example projects

More to be published soon.

Dependencies

~8–21MB
~231K SLoC