interactcli-rs is a command-line program framework used to solve the problem of the integration of command-line and interactive modes, including functions such as unification of command-line interactive modes and sub-command prompts. The framework integrates clap and shellwords.

Overview

interactcli-rs

简体中文

interactcli-rs is a command-line program framework used to solve the problem of the integration of command-line and interactive modes, including functions such as unification of command-line interactive modes and sub-command prompts. The framework integrates clap and shellwords.

quick guide

The frame contains examples of visiting www.baidu.com

The quick start process is as follows:

  • clone project

    git clone https://github.com/jiashiwen/interactcli-rs.git
    cd interactcli-rs
  • Command line mode

    cargo run requestsample baidu
  • Interactive mode

    cargo run -- -i
    interact-rs> requestsample baidu

Interactive mode

Use "Tab" key in interactive mode to prompt command

Development steps

  • Define commands The cmd module is used to define commands and related subcommands

    use clap::App;
    
    pub fn new_requestsample_cmd() -> App<'static> {
        clap::App::new("requestsample")
            .about("requestsample")
            .subcommand(get_baidu_cmd())
    }
    
    pub fn get_baidu_cmd() -> App<'static> {
        clap::App::new("baidu").about("request www.baidu.com")
    }
    

    The new_requestsample_cmd function defines the command "requestsample", and the get_baidu_cmd function defines the subcommand baidu of requestsample

  • Register order The command tree is defined in the src/cmd/rootcmd.rs file, and the defined subcommands can be registered here

    lazy_static! {
      static ref CLIAPP: clap::App<'static> = App::new("interact-rs")
          .version("1.0")
          .author("Shiwen Jia. <[email protected]>")
          .about("command line sample")
          .arg(
              Arg::new("config")
                  .short('c')
                  .long("config")
                  .value_name("FILE")
                  .about("Sets a custom config file")
                  .takes_value(true)
          )
          .arg(
              Arg::new("interact")
                  .short('i')
                  .long("interact")
                  .about("run as interact mod")
          )
          .arg(
              Arg::new("v")
                  .short('v')
                  .multiple_occurrences(true)
                  .takes_value(true)
                  .about("Sets the level of verbosity")
          )
          .subcommand(new_requestsample_cmd())
          .subcommand(new_config_cmd())
          .subcommand(new_multi_cmd())
          .subcommand(new_task_cmd())
          .subcommand(
              App::new("test")
                  .about("controls testing features")
                  .version("1.3")
                  .author("Someone E. <[email protected]>")
                  .arg(
                      Arg::new("debug")
                          .short('d')
                          .about("print debug information verbosely")
                  )
          );
      static ref SUBCMDS: Vec<SubCmd> = subcommands();
      }
    

    The defined command does not need other processing, the framework will generate a sub-command tree when the system is running, for the support of the command prompt

  • Parse command The cmd_match in src/cmd/rootcmd.rs is responsible for parsing commands, and the parsing logic can be written in this function

    fn cmd_match(matches: &ArgMatches) {   
      if let Some(ref matches) = matches.subcommand_matches("requestsample") {
          if let Some(_) = matches.subcommand_matches("baidu") {
              let rt = tokio::runtime::Runtime::new().unwrap();
              let async_req = async {
                  let result = req::get_baidu().await;
                  println!("{:?}", result);
              };
              rt.block_on(async_req);
          };
      }
    }
  • Modify the command prompt in interactive mode The prompt can be defined in src/interact/cli.rs

    pub fn run() {
      
      ...
    
      loop {
          let p = format!("{}> ", "interact-rs");
          rl.helper_mut().expect("No helper").colored_prompt = format!("\x1b[1;32m{}\x1b[0m", p);
    
          ...
      }
      
      ...
    }
    
You might also like...
A git sub-command to view your git repository in the web browser
A git sub-command to view your git repository in the web browser

git-view A git sub-command to view your git repository in the web browser! About Are you also frustrated from moving your hands away from the keyboard

A template with cookie cutter CLI, Program and Integration tests for Solana blockchain
A template with cookie cutter CLI, Program and Integration tests for Solana blockchain

About solana-cli-program template is a sample app demonstrating the creation of a minimal CLI application written in Rust to interact with Solana and

Benchmarking C, Python, and Rust on the "sp" problem

Fast SP Various implementations of the problem in this blog post. Requirements To run this, you will need Rust Nightly and Python 3.8+ with numpy. Rus

Red-blue graph problem solver - Rust implementation
Red-blue graph problem solver - Rust implementation

Red-blue graph problem solver - Rust implementation The problem is the following: In a directed graph, each node is colored either red or blue. Furthe

Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.
Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.

Leetcode TUI Use Leetcode in your terminal. Why this TUI: My motivation for creating leetcode-tui stemmed from my preference for tools that are lightw

solve scripts for all 3 of @0xhana's paradigm ctf challs!

hana solana ctf ok like all the best software engineers i got the technicals done on time and under budget but left documentation for future me. its n

Trying to solve Advent of Code 2022 in 25 different languages (1 day = 1 language)

Advent of Code 2022: 15/25 langs I’ll try to solve this Advent of Code using different language for each day. Any programs needed to run the code will

lace up GFA files using panSN path name sub-ranges to coordinate the lacing

gfalace gfalace is a Rust-based tool designed to process a collection of GFA (Graphical Fragment Assembly) files. It aims to interpret the path names

Black-box integration tests for your REST API using the Rust and its test framework

restest Black-box integration test for REST APIs in Rust. This crate provides the [assert_api] macro that allows to declaratively test, given a certai

Comments
  • 是否支持类似clishe一样,进入子命令的上下文

    是否支持类似clishe一样,进入子命令的上下文

    命令行交互式程序,可能有进入子命令的context,在子命令模式下,有一批可以使用的子命令;有点类似交换机那种

    [XXXX] interface ethernet 0/0/0
    [Switch- ethernet 0/0/0] speed 10
    [Switch- ethernet 0/0/0] duplex full
    

    interface ethernet 0/0/0 输入之后,可以方便地定义子命令形式,只允许 speed [10/100/1000] 或 duplex [full half] 的形式

    opened by RickSKy 0
Owner
JiaShiwen
Old architect
JiaShiwen
A Rust library for building interactive prompts

inquire is a library for building interactive prompts on terminals. Demo Source Usage Put this line in your Cargo.toml, under [dependencies]. inquire

Mikael Mello 426 Dec 26, 2022
Requestty - An easy-to-use collection of interactive cli prompts inspired by Inquirer.js.

Requestty requestty (request-tty) is an easy-to-use collection of interactive cli prompts inspired by Inquirer.js. Easy-to-use - The builder API and m

null 160 Dec 28, 2022
languagetool-code-comments integrates the LanguageTool API to parse, spell check, and correct the grammar of your code comments!

languagetool-code-comments integrates the LanguageTool API to parse, spell check, and correct the grammar of your code comments! Overview Install MacO

Dustin Blackman 17 Dec 25, 2022
Simple OpenAI CLI wrapper written in Rust, feat. configurable prompts and models

Quick Start git clone https://github.com/ryantinder/ask-rs cd ask cargo install --path . Example ask tell me about the Lockheed Martin SR71 >> The Loc

Ryan Tinder 3 Aug 9, 2023
Beautiful, minimal, opinionated CLI prompts inspired by the Clack NPM package

Effortlessly build beautiful command-line apps with Rust ?? ✨ Beautiful, minimal, opinionated CLI prompts inspired by the @clack/prompts npm package.

Alexander Fadeev 7 Jul 23, 2023
osu! difficulty and pp calculation for all modes

rosu-pp-js Difficulty and performance calculation for all osu! modes. This is a js binding to the Rust library rosu-pp which was bootstrapped through

Max 8 Nov 23, 2022
osu! difficulty and pp calculation for all modes

rosu-pp-py Difficulty and performance calculation for all osu! modes. This is a python binding to the Rust library rosu-pp which was bootstrapped thro

Max 16 Dec 28, 2022
A high-performance WebSocket integration library for streaming public market data. Used as a key dependency of the `barter-rs` project.

Barter-Data A high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges - batteries includ

Barter 23 Feb 3, 2023
Most intuitive global cli maker. *(lazy_static + config-rs + clap)

argone Most intuitive global cli maker. *(lazy_static + config-rs + clap) | Examples | Docs | Latest Note | [dependencies] argone = "0.5" Phases Parsi

Doha Lee 6 Dec 9, 2022
Grid-based drum sequencer plugin as MIDI FX in CLAP/VST3 format

dr-seq Grid-based drum sequencer plugin as MIDI FX in CLAP/VST3 format. WARNING: This project is in a very early state. So there is no guarantee for a

Oliver Rockstedt 6 Jan 29, 2023