A command parsing library

Related tags

CLI LampOpt
Overview

LampOpt操作文档

概述

LampOpt是一个基于C++的控制台命令解析库,优点是体型小、适应全平台、方便易用。

引用

可选择在IDE中直接在引用目录中添加odt.h,或直接与需编译文件放在同一目录下,并引用: #include "odt.h"

使用

odt.h头文件内定义了一个名为LampOptnamespace,其中有以下内容:

struct CommandRead{//用于存储读取成功的参数的结构体
		std::string CommandName; //参数名称
		int argvl;//该参数对应的参数值在argv[]中的开始下标
		int argvr;//该参数对应的参数值在argv[]中的停止下标
};

和一个函数std::vector getopt,用于读取命令,其原型如下:

std::vector getopt(int argc,char *argv[],std::vectorSettings)

返回结果为一个std::vector类型的容器,下标依次列出了每条参数。

参数argc与参数argv[]为main函数的形参,最后的参数std::vectorSettings为参数的配置文件,其书写规则如下:

  1. 从第一个参数开始,分别填写长参数与短参数,如第一个参数填写--help,而第二个参数填写-h时,则--help的长参数将与-h的短参数绑定。
  2. 如果一个参数的长参数与短参数完整,则返回的CommandRead结构体中CommandName将会返回短参数的名称。
  3. 长参数开头应带有--,短参数开头应带有-,而短参数必须带有-,长参数不做要求。
  4. 可以选择不设置长参数或短参数,只需要在该参数位置填写none即可,如果短参数位置填写none,则返回的CommandRead结构体中CommandName将会返回长参数的名称。
  5. 不允许长参数与短参数均填写none的情况存在。
  6. 不允许Settings内元素个数为奇数的情况,这种情况下一定不合法。
  7. 如果有类似tar -xzf的情况出现,返回的数组中将依次返回x、z、f,参数值共享。

如下为简单使用实例可以读取参数并输出读取到的参数与对应参数值:

#include #include using namespace std; int main(int argc,char *argv[]){ vectorstr={//参数设置初始化 "--test","-t", "--help","-h" }; vectorRet=LampOpt::getopt(argc,argv,str);//接收读取结果 for(int i=0;i
#include "opt.h"
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(int argc,char *argv[]){
	vectorstr={//参数设置初始化
		"--test","-t",
		"--help","-h"
	};
	vectorRet=LampOpt::getopt(argc,argv,str);//接收读取结果
	for(int i=0;isize();i++){
		cout<CommandName<<" ";//输出参数名称
		for(int j=Ret[i].argvl;j<=Ret[i].argvr;j++)//依次枚举参数
			cout<" ";//输出参数值
		cout<return 0;
}

报错信息

Argument setting error:编程者的参数设置错误,详见上文中的定义要求。

Unknown argument:用户的参数输入错误。

Owner
东灯
Be Myself
东灯
null 76 Apr 18, 2022
Command-line flag parsing in C

flag.h Inspired by Go's flag module: https://pkg.go.dev/flag WARNING! The design of the library is not finished and may be a subject to change. Quick

Tsoding 36 Jun 26, 2022
easy to use, powerful & expressive command line argument parsing for modern C++ / single header / usage & doc generation

clipp - command line interfaces for modern C++ Easy to use, powerful and expressive command line argument handling for C++11/14/17 contained in a sing

André Müller 888 Jun 30, 2022
Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers.

What is it? Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers. The Java version is

Google 13.9k Jul 4, 2022
A lightweight utility for parsing PE file formats (EXE, DLL, SYS) written in C/C++

peParser A lightweight utility for parsing PE file formats (EXE, DLL, SYS). Windows Portable Executable (PE) files includes a variety of parsable data

null 6 Jun 15, 2022
A library for interactive command line interfaces in modern C++

cli A cross-platform header only C++14 library for interactive command line interfaces (Cisco style) Features Header only Cross-platform (linux and wi

Daniele Pallastrelli 803 Jul 2, 2022
C++ Library for pulling system and hardware information, without hitting the command line.

infoware C++ Library for pulling system and hardware information, without hitting the command line. Requirements No non-built-in ones by default. Some

The Phantom Derpstorm 287 Jun 27, 2022
A simple to use, composable, command line parser for C++ 11 and beyond

Clara v1.1.5 !! This repository is unmaintained. Go here for a fork that is somewhat maintained. !! A simple to use, composable, command line parser f

Catch Org 651 Jun 15, 2022
CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface.

CLI11: Command line parser for C++11 What's new • Documentation • API Reference CLI11 is a command line parser for C++11 and beyond that provides a ri

null 2.1k Jul 5, 2022
Lightweight C++ command line option parser

Release versions Note that master is generally a work in progress, and you probably want to use a tagged release version. Version 3 breaking changes I

null 3.1k Jul 6, 2022
A simple to use, composable, command line parser for C++ 11 and beyond

Lyra A simple to use, composing, header only, command line arguments parser for C++ 11 and beyond. Obtain License Standards Stats Tests License Distri

Build Frameworks Group 343 Jul 4, 2022
CLIp is a clipboard emulator for a command line interface written in 100% standard C only. Pipe to it to copy, pipe from it to paste.

CLIp v2 About CLIp is a powerful yet easy to use and minimal clipboard manager for a command line environment, with no dependencies or bloat. Usage Sy

A.P. Jo. 12 Sep 18, 2021
pbr2gltf2 is a command line tool for converting PBR images to a glTF 2.0 material.

pbr2gltf2 is a command line tool for converting PBR images to a glTF 2.0 material. The tool is detecting depending on the filename, which PBR information is stored. It swizzles the images and does reassign the channels to a glTF 2.0 image. The tool stores the images plus a minimal, valid glTF 2.0 file containing the required material, textures and images.

UX3D GmbH 22 Jan 11, 2022
led is a line-oriented text editor in command line

led is a line-oriented text editor in command line. This editor is similar to the standard program on unix systems - GNU ed. But i'm not going to make an exact clone of that program, it's just a pet project.

Artem Mironov 9 Jun 14, 2022
A command-line tool to display colorful distro information.

sjfetch A command-line tool to display colorful distro information.

Fikret Musk 6 Apr 6, 2022
Command-Based Text Editor written in cpp using Linked Lists and Stack

Command Based Text Editor Our goal in this project is to write a command-based text editor in cpp using linked lists and stack. This text editor will

bedirhanbardakci 3 Jun 9, 2021
LwSHELL is lightweight, platform independent, command line shell for embedded systems.

LwSHELL is lightweight, platform independent, command line shell for embedded systems. It targets communication with embedded systems from remote terminal to quickly send commands and the retrieve data from the device.

Tilen Majerle 60 Jun 26, 2022
Toybox: all-in-one Linux command line.

Toybox: all-in-one Linux command line.

Rob Landley 1.7k Jun 29, 2022
Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

GPUOpen Effects 174 Jun 26, 2022