All Projects → ksk001100 → Seahorse

ksk001100 / Seahorse

Licence: mit
A minimal CLI framework written in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Seahorse

classy
Super simple text classifier using Naive Bayes. Plug-and-play, no dependencies
Stars: ✭ 12 (-90.91%)
Mutual labels:  minimal, easy
Easy.common
A set of useful utilities and helpers used across Easy.* projects.
Stars: ✭ 306 (+131.82%)
Mutual labels:  easy-to-use, easy
DM-BOT
📧 DM-BOT is discord bot that can record direct messages. One of us! You can also reply to those messages! DM-BOT is easy to use & understand! I decided to use Discord.js, it's literally the best.
Stars: ✭ 31 (-76.52%)
Mutual labels:  easy-to-use, easy
Tkinter-Designer
An easy and fast way to create a Python GUI 🐍
Stars: ✭ 4,697 (+3458.33%)
Mutual labels:  easy-to-use, easy
Art
🎨 ASCII art library for Python
Stars: ✭ 1,026 (+677.27%)
Mutual labels:  easy-to-use, easy
discord.json
Discord.json | Make your own discord bot with json !
Stars: ✭ 27 (-79.55%)
Mutual labels:  easy-to-use, easy
Django Admin Easy
Collection of admin fields and decorators to help to create computed or custom fields more friendly and easy way
Stars: ✭ 265 (+100.76%)
Mutual labels:  easy-to-use, easy
Webpack Nano
A teensy, squeaky 🐤 clean Webpack CLI
Stars: ✭ 199 (+50.76%)
Mutual labels:  cli, minimal
Ezxss
ezXSS is an easy way for penetration testers and bug bounty hunters to test (blind) Cross Site Scripting.
Stars: ✭ 1,022 (+674.24%)
Mutual labels:  easy-to-use, easy
Tic Tac
Client not paid ? This is the solution of your problem
Stars: ✭ 29 (-78.03%)
Mutual labels:  easy-to-use, easy
easymail
Easy way to install a mail server.
Stars: ✭ 60 (-54.55%)
Mutual labels:  easy-to-use, easy
Cli
Get a programmable email address. Automate what happens when you receive emails. It's like Zapier for devs who hate emails.
Stars: ✭ 105 (-20.45%)
Mutual labels:  cli, easy-to-use
CyberPunkNetrunner
Cyberpunk 2077 Netrunner Hacking Tool (Easy to use and install). Don't use it on illegal and malicious activity. Inspired by the game CyberPunk 2077 https://www.cyberpunk.net/
Stars: ✭ 69 (-47.73%)
Mutual labels:  easy-to-use, easy
Lang-app
Add a multi lang configuration to your WEB APP 'from scratch' [ANY FRAMEWORK, ANY PLUGIN, ANY API]
Stars: ✭ 15 (-88.64%)
Mutual labels:  easy-to-use, easy
ytmous
Anonymous Youtube Proxy
Stars: ✭ 60 (-54.55%)
Mutual labels:  easy-to-use, easy
CNN Own Dataset
CNN example for training your own datasets.
Stars: ✭ 25 (-81.06%)
Mutual labels:  easy-to-use, easy
Easy.messagehub
No need for .NET Events! A thread-safe, high performance & easy to use cross platform implementation of the Event Aggregator Pattern.
Stars: ✭ 208 (+57.58%)
Mutual labels:  easy-to-use, easy
Ezshare
Easily share files, folders and clipboard over LAN - Like Google Drive but without internet
Stars: ✭ 182 (+37.88%)
Mutual labels:  cli, easy
Yaspin
A lightweight terminal spinner for Python with safe pipes and redirects 🎁
Stars: ✭ 413 (+212.88%)
Mutual labels:  cli, easy-to-use
Nat
nat - the 'ls' replacement you never knew you needed
Stars: ✭ 1,129 (+755.3%)
Mutual labels:  cli, easy-to-use

seahorse

crates.io releases count issues count forks count license github actions CI

Logo

A minimal CLI framework written in Rust

Features

  • Easy to use
  • No dependencies
  • Typed flags(Bool, String, Int, Float)

Documentation

Here

Usage

To use seahorse, add this to your Cargo.toml:

[dependencies]
seahorse = "1.1"

Example

Run example

$ git clone https://github.com/ksk001100/seahorse
$ cd seahorse
$ cargo run --example single_app -- --help
$ cargo run --example multiple_app -- --help

Quick Start

$ cargo new cli
$ cd cli
$ echo 'seahorse = "*"' >> Cargo.toml
use seahorse::{App};
use std::env;

fn main() {
    let args: Vec<String> = env::args().collect();
    let app = App::new(env!("CARGO_PKG_NAME"))
        .description(env!("CARGO_PKG_DESCRIPTION"))
        .author(env!("CARGO_PKG_AUTHORS"))
        .version(env!("CARGO_PKG_VERSION"))
        .usage("cli [args]")
        .action(|c| println!("Hello, {:?}", c.args));

    app.run(args);
}
$ cargo build --release
$ ./target/release/cli --help
$ ./target/release/cli John

Multiple command application

use seahorse::{App, Context, Command};
use std::env;

fn main() {
    let args: Vec<String> = env::args().collect();
    let app = App::new(env!("CARGO_PKG_NAME"))
        .description(env!("CARGO_PKG_DESCRIPTION"))
        .author(env!("CARGO_PKG_AUTHORS"))
        .version(env!("CARGO_PKG_VERSION"))
        .usage("cli [name]")
        .action(default_action)
        .command(add_command())
        .command(sub_command());

    app.run(args);
}

fn default_action(c: &Context) {
    println!("Hello, {:?}", c.args);
}

fn add_action(c: &Context) {
    let sum: i32 = c.args.iter().map(|n| n.parse::<i32>().unwrap()).sum();
    println!("{}", sum);
}

fn add_command() -> Command {
    Command::new("add")
        .description("add command")
        .alias("a")
        .usage("cli add(a) [nums...]")
        .action(add_action)
}

fn sub_action(c: &Context) {
    let sum: i32 = c.args.iter().map(|n| n.parse::<i32>().unwrap() * -1).sum();
    println!("{}", sum);
}

fn sub_command() -> Command {
    Command::new("sub")
        .description("sub command")
        .alias("s")
        .usage("cli sub(s) [nums...]")
        .action(sub_action)
}
$ cli John
Hello, ["John"]

$ cli add 32 10 43
85

$ cli sub 12 23 89
-124

Branch processing by flag

use seahorse::{App, Command, Context, Flag, FlagType, error::FlagError};
use std::env;

fn main() {
    let args: Vec<String> = env::args().collect();
    let app = App::new(env!("CARGO_PKG_NAME"))
        .description(env!("CARGO_PKG_DESCRIPTION"))
        .author(env!("CARGO_PKG_AUTHORS"))
        .version(env!("CARGO_PKG_VERSION"))
        .usage("cli [name]")
        .action(default_action)
        .flag(
            Flag::new("bye", FlagType::Bool)
                .description("Bye flag")
                .alias("b"),
        )
        .flag(
            Flag::new("age", FlagType::Int)
                .description("Age flag")
                .alias("a"),
        )
        .command(calc_command());

    app.run(args);
}

fn default_action(c: &Context) {
    if c.bool_flag("bye") {
        println!("Bye, {:?}", c.args);
    } else {
        println!("Hello, {:?}", c.args);
    }

    if let Ok(age) = c.int_flag("age") {
        println!("{:?} is {} years old", c.args, age);
    }
}

fn calc_action(c: &Context) {
    match c.string_flag("operator") {
        Ok(op) => {
            let sum: i32 = match &*op {
                "add" => c.args.iter().map(|n| n.parse::<i32>().unwrap()).sum(),
                "sub" => c.args.iter().map(|n| n.parse::<i32>().unwrap() * -1).sum(),
                _ => panic!("undefined operator..."),
            };

            println!("{}", sum);
        }
        Err(e) => match e {
            FlagError::Undefined => panic!("undefined operator..."), 
            FlagError::ArgumentError => panic!("argument error..."), 
            FlagError::NotFound => panic!("not found flag..."), 
            FlagError::ValueTypeError => panic!("value type mismatch..."), 
            FlagError::TypeError => panic!("flag type mismatch..."), 
        },
    }
}

fn calc_command() -> Command {
    Command::new("calc")
        .description("calc command")
        .alias("cl, c")
        .usage("cli calc(cl, c) [nums...]")
        .action(calc_action)
        .flag(
            Flag::new("operator", FlagType::String)
                .description("Operator flag(ex. cli calc --operator add 1 2 3)")
                .alias("op"),
        )
}
$ cli John
Hello, ["John"]

$ cli John --bye
Bye, ["John"]

$ cli John --age 10
Hello, ["John"]
["John"] is 10 years old

$ cli John -b -a=40
Bye, ["John"]
["John"] is 40 years old

$ cli calc --operator add 1 2 3 4 5
15

$ cli calc -op sub 10 6 3 2
-21

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under MIT license

Code of Conduct

Contribution to the seahorse crate is organized under the terms of the Contributor Covenant, the maintainer of seahorse, @ksk001100, promises to intervene to uphold that code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].