Command line parser linux

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Command line parsing utility for Bash shell scripts.

License

gabeg805/lib-commandline-parser-bash

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

The Command Line Parser is an easy to use command line parser for Bash shell scripts. The interface is such that you:

  1. Use the cli_options() function to:
    • Define the command line options.
    • Define arguments for the option, if any.
    • Give a description of what the command does.
  2. Parse the input options with the cli_parse() function.
  3. Call the cli_get() function to retrieve your options for a given option.

It is also possible to print out command line usage, if the user should required it, via the cli_usage() function, which is generated automatically from all the information provided in Step 1.

A standard way of initializing your command line options would be something like:

cli_options "-h|--help |Print program usage." \ "-o|--option=required:|Option with a required argument." \ " |--another-option |Just a long option, no short option and no argument." \ "-s|--stuff=optional::|Optional argument for this option." \ "-t|--things=list. |Do things with this list argument." \ "-v|--verbose |Verbose output." cli_parse "$" . option=$(cli_get "option") another=$(cli_get "another-option") stuff=$(cli_get "stuff") things=$(cli_get "things") . 

When calling cli_get(), use the long option name, without the leading two dashes. However, if no long option name exists, use the short option without the leading dash.

Читайте также:  Astra linux значок сети

For more information on the types of arguments and the meaning behind the color character, click here.

If this file resides under your PATH environment variable, then in a shell script, you can source it simply with either:

If it does not reside under the PATH, you will need to give the full or relative path to commandline.sh.

Remove the file from where you copied it and delete the line above, which sources it.

When declaring command line options, there are various different types of arguments that can be used. They are denoted by the use of ‘:’ characters after the argument name in the long option section.

  • argument = This option does not take an argument.
  • argument: = This option takes a single, required argument.
  • argument:: = This option may or may not take an argument.
  • argument. = This argument takes one or more arguments. Arguments stop being read once a new option is encountered.

About

Command line parsing utility for Bash shell scripts.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A lightweight cross-platform getopt alternative that works on Linux, Windows and macOS. Command line argument parser library for C/C++. Can be used to parse argv and argc parameters.

License

likle/cargs

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

libcargs — command line argument library for C/C++

This is a lighweight C command line argument library. It is currently compiled and tested under Windows, MacOS and Linux.

Please have a look at the reference for detailed information. Some features this library includes:

  • cross-platform on windows, linux and macOS
  • simple interface — just one header
  • one simple loop — to iterate over the arguments
  • automatic help output — showing all options available
  • long and short options — giving users alternatives
  • option values — for options which are more than just flags
Читайте также:  Man pages linux manual

Building, embedding and testing instructions are available in the documentation (it’s very easy).

All the documentation is available in the the github page of this repository.

#include #include #include /** * This is the main configuration of all options available. */ static struct cag_option options[] = < identifier = 's', .access_letters = "s", .access_name = NULL, .value_name = NULL, .description = "Simple flag">, identifier = 'm', .access_letters = "mMoO", .access_name = NULL, .value_name = NULL, .description = "Multiple access letters">, identifier = 'l', .access_letters = NULL, .access_name = "long", .value_name = NULL, .description = "Long parameter name">, identifier = 'k', .access_letters = "k", .access_name = "key", .value_name = "VALUE", .description = "Parameter value">, identifier = 'h', .access_letters = "h", .access_name = "help", .description = "Shows the command help">>; /** * This is a custom project configuration structure where you can store the * parsed information. */ struct demo_configuration < bool simple_flag; bool multiple_flag; bool long_flag; const char *key; >; int main(int argc, char *argv[]) < char identifier; const char *value; cag_option_context context; struct demo_configuration config = NULL>; int param_index; /** * Now we just prepare the context and iterate over all options. Simple! */ cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv); while (cag_option_fetch(&context)) < identifier = cag_option_get(&context); switch (identifier) < case 's': config.simple_flag = true; break; case 'm': config.multiple_flag = true; break; case 'l': config.long_flag = true; break; case 'k': value = cag_option_get_value(&context); config.key = value; break; case 'h': printf("Usage: cargsdemo [OPTION]. \n"); printf("Demonstrates the cargs library.\n\n"); cag_option_print(options, CAG_ARRAY_SIZE(options), stdout); printf("\nNote that all formatting is done by cargs.\n"); return EXIT_SUCCESS; > > printf("simple_flag: %i, multiple_flag: %i, long_flag: %i, key: %s\n", config.simple_flag, config.multiple_flag, config.long_flag, config.key ? config.key : "-"); for (param_index = context.index; param_index  argc; ++param_index) < printf("additional parameter: %s\n", argv[param_index]); > return EXIT_SUCCESS; >
foo@bar:~$ ./cargsdemo simple_flag: 0, multiple_flag: 0, long_flag: 0, key: -
foo@bar:~$ ./cargsdemo -k=test -sm --long simple_flag: 1, multiple_flag: 1, long_flag: 1, key: test
foo@bar:~$ ./cargsdemo --help Usage: cargsdemo [OPTION]. Demonstrates the cargs library. -s Simple flag -m, -M, -o, -O Multiple access letters --long Long parameter name -k, --key=VALUE Parameter value -h, --help Shows the command help Note that all formatting is done by cargs.
foo@bar:~$ ./cargsdemo also -k=test some -sm additional --long parameters simple_flag: 1, multiple_flag: 1, long_flag: 1, key: test additional parameter: also additional parameter: some additional parameter: additional additional parameter: parameters

About

A lightweight cross-platform getopt alternative that works on Linux, Windows and macOS. Command line argument parser library for C/C++. Can be used to parse argv and argc parameters.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

NoumanRnD/Linux-Command-Line-Parser-

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Strengthening students’ skills in gaining new knowledge in C coding particularly, with string processing and pointers #Description Homeworks 3 and 4 will involve developing a basic shell (command line interpreter) for Linux.
In this assignment, HW3, you will build the portion of the shell that parses a user-entered command
sequence so that it can later be executed. In this portion of the assignment you are only building a
parser for the commands, you don’t actually execute them yet. Instead you print out the details of
the parsed commands.
You are given a skeleton code and required to build on it to achieve this task. The user entry is a
number of commands with their arguments, if any, separated by pipes, if any.
Here are some valid, sample inputs:
ls –la
ls –la | wc –l
ls | grep “something” | sort | wc –l

A basic shell is just an infinite loop that prints a print, receives a line of user input, and executes the
appropriate programs. In this assignment, you will only write the parser.
Consider the following pseudo-code for this assignment:

Infinite loop
The program displays a prompt,
The user enters a commands on a line,
The program reads the line, if the user entry is spaces or empty line, then perform next iteration of the
loop i.e., continue
if the user entry is a special command, exit, then exit the loop i.e., break
Parse the commands, i.e., recognize the commands and store them in an array of a
given formatted structure,
Call a provided function, print_commands, to display the information about
these commands
Display the prompt again, waiting for the user to enter another command.
end

Источник

Оцените статью
Adblock
detector