command_rpc

image

A command-line rpc written in Rust. It build on top of the well-known king of rust cli crates, clap. Most of its features are preserved but the usage of command_rpc shortens the boilerplate code.

Official release: May 29th - There is going to be a tutorial on youtube, also linked here!

Why to use command_rpc

What crpc is made for

Of course, that could be a disadvantage, you should not use crpc for big and well-defaultized transfer protocolls - and you may not use it for i/o-intense programs.

Advantages to pure clap

Usage of command_rpc

Installation

Run cargo add command-rpc shell command or insert command-rpc = "*" in your Cargo.toml. Just now, in v0.1.12 this tools stands at the beginning of its development.

Example

use command_rpc::crpc_main;

#[crpc_main]
pub mod my_cli_backend {
   use command_rpc::{cprc_mod, crpc_fn};

   #[cprc_fn]
   pub fn greet(
       /// The name of the person you want to greet.
       name: str
    ) {
      eprintln!("Hello, {}!", name);
  }

  #[crpc_mod]
  pub mod my_cli_backend_sub {
    use command_rpc::cprc_fn;

    #[crpc_fn]
    pub fn friendly_greet(
        /// The name of the person you want to greet.
        name: str,
        /// the adjective you want to use in the greeting.
        adjective: str 
     ) {
       eprintln!("Hello, {}! You are {}!", name, adjective);
     }
   }
}
fn main() {
   My_cli_mod::parse().delegate();
}

How to use crpc

  1. Add command-rpc as dependency.
  2. Write a crpc module that has the #[crpc_main] attribute. The functions (that need to be public!) in it you annotate with #[crpc_fn] is going to be nested as command, and (public) modules with #[crpc_mod] included as subcommand, its inner (public) functions will be included too. Also comments will be extracted out of the function signature - other comments are extracted like working with clap. (Better check out our examples –> https://docs.rs/command-rpc/0.1.12/command_rpc/ )
  3. Import the needed proc macros with use command_rpc::*.
  4. Give the main.rs file access to this module. Your main function looks as follows:

     fn main() {
       [name of your crpc_main module, first letter kapital]_::parse().delegate();
     }
    
  5. Now you can expand, build or compile your program. Don´t worry about error reports at first, most of them disappear after first build and expansion. Check out Advices below for more information about usage recommendations and things that might not work correctly yet.

Advice

Contribution

To do so, you may write for longer collaboration a message to me (Mail: loos-johannes@gmx.de, Instagram: lsjohannes), or open directly a pr.


Version overview/preview