RCLIP-CMD (Rust Command Line Interface Parser)

RCLIP-CMD (Rust Command Line Interface Parser) is a Rust library designed to simplify the process of parsing command-line arguments and options for your Rust applications. With RCLIP-CMD, you can easily define and manage command-line options, parse arguments, and access the values of specified options.

Table of Contents 1. Features 2. Getting Started - Add RCLIP-CMD to Your Dependencies - Import Necessary Modules - Define Your Command-Line Options 3. Example - Defining Command-Line Options - Creating an OptionsManager Instance - Parsing Command-Line Arguments - Checking if Options Are Present - Handling Errors 4. License 5. Disclaimer

1. Features

2. Getting Started

To get started with RCLIP-CMD, follow these steps:

1. Add RCLIP-CMD to Your Dependencies

To use RCLIP-CMD in your Rust project, add it to your Cargo.toml file as a dependency:

toml [dependencies] rclip-cmd = "1.0.0"

This step ensures that your project can access the RCLIP-CMD library.

2. Import Necessary Modules

In your Rust code, import the modules and types provided by RCLIP-CMD to use its functionality:

rust use std::env; use rclip_cmd::{options_manager::OptionsManager, option::Option};

Here, we import the necessary modules from RCLIP-CMD, including OptionsManager and Option, which are essential for defining and managing command-line options.

3. Define Your Command-Line Options

Before you can parse command-line arguments, you need to define the options for your application using the Option struct from RCLIP-CMD. Each option is configured with a short name, a long name, and additional information about whether it is required and whether it expects an argument.

3. Example

Here's a detailed example of how to use RCLIP-CMD to define, parse, and work with command-line options in Rust:

1. Defining Command-Line Options

In this part of the code, we define the command-line options for our application using the Option struct from RCLIP-CMD. Each option is configured with various properties:

rust let options = vec![ Option::new("v".to_string(), "version".to_string(), false, false, "Prints version information".to_string()), Option::new("o".to_string(), "output".to_string(), false, false, "The output file to write to".to_string()), Option::new("i".to_string(), "input".to_string(), true, true, "The input file".to_string()), ];

2. Creating an OptionsManager Instance

After defining the command-line options, we create an OptionsManager instance to manage these options and handle argument parsing:

rust let mut options_manager = OptionsManager::new("Test Application", options);

3. Parsing Command-Line Arguments

Next, we parse the command-line arguments using the parse_options function:

rust let result = options_manager.parse_options(env::args().collect());

4. Checking if Options Are Present

We use various functions provided by the OptionsManager instance to check if specific options are present and retrieve their argument values:

rust if options_manager.is_present("v") { println!("Version 0.1.0"); } if options_manager.is_present("i") { let argument = options_manager.argument("i"); println!("Input: {}", argument); } if options_manager.is_present("o") { let argument = options_manager.argument("o"); println!("Output: {}", argument); }

5. Handling Errors

Lastly, we handle any errors that might occur during argument parsing:

rust else { println!("Error: {}", result.err().unwrap()); }

This code provides a complete example of how to define, manage, parse, and work with command-line options in Rust using the RCLIP-CMD library.

4. License

This code is licensed under the GNU General Public License, version 3.0 (GPL-3.0).

5. Disclaimer

This code is provided as-is, and the authors make no warranties regarding its correctness or fitness for any purpose. Please feel free to report issues or submit pull requests to improve this code.