Aptivi - Manual
ProjectsWebsiteBlog
Terminaux - Manual
Terminaux - Manual
  • Welcome!
  • Breaking changes
    • API v1.0
    • API v2.0
    • API v3.0
    • API v4.0
    • API v5.0
    • API v6.0
    • API v7.0
  • Usage
    • Preface
    • Console Tools
      • Console Checker
        • Console Size Requirements
      • Image Rendering
        • Icons
      • Console Writers
        • Individual Writers
        • Cyclic Writers
          • Geometric Shapes
          • Charts
          • Text
          • Artistic
          • Progress Bars
          • Lists and Calendars
          • Miscellaneous
        • Informational Boxes
      • Textual UI
        • Interactive TUI
        • Console Screen
        • Console Resize Listener
        • VT Sequences
      • Console Wrapper
      • Console Colors
      • Color Templates
      • Presentation System
      • Console Extensions
      • Nerd Fonts
      • Terminal Info
      • Test Fixtures
      • Terminal Structures
      • Console Logging
    • Input Reader
      • Shells
        • Shell Structure
          • Help System
          • Command Parsing
          • Command Information
          • Command Switches
          • Shell Presets
          • Command Aliasing
      • Other Input
        • Keybindings
        • Choice-based inputs
        • Editors and Viewers
        • Figlet Font Selector
        • Color Wheel
        • Spinner Selector
      • Reader State
      • Reader Settings
      • Syntax Highlighting
      • Pointer Events
    • Color Sequences
      • Color Model Conversions
      • Color Model Parsing
      • Interop with System.Drawing.Color
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Command-line Arguments
  • Switch Management
  • Special characters
Edit on GitHub
  1. Usage
  2. Input Reader
  3. Shells
  4. Shell Structure

Command Parsing

How command parsing works

Last updated 4 months ago

Once the GetLine() function gets your input, it attempts to split any command with the semicolon between them, like:

command1 arg1 arg2 ; command2 arg3 arg4

Any command that starts with either a space or a hashtag will be ignored as a comment, like: (Notice the extra space in the first comment)

 comment
#comment

The first word is a command, and all words following it in a single command text are the series of arguments. These words then get split to arguments (without the switch indicator -switch) and switches (arguments that come after the dash) using the ProvidedArgumentsInfo class, though it does much more than that.

This class contains these variables:

  • Command: Target command

  • ArgumentsText: Provided arguments and switches

  • ArgumentsList: Array of arguments without the switches

  • SwitchesList: Array of switches

  • RequiredArgumentsProvided: Checks to see if the arguments are provided or not

  • RequiredSwitchesProvided: Checks to see if the required switches are provided or not

  • RequiredSwitchArgumentsProvided: Checks to see if the required switch arguments are provided or not

After the above class constructor is called, the shell attempts to execute an alias command, if found. Else, the built-in command is going to be executed.

Finally, the command executor thread is fired up with the ExecuteCommandParameters instance to hold command execution parameters for the same thread. The thread is then started.

Command-line Arguments

The command-line arguments feature is backported from Nitrocid KS with more customization in place. This allows you to create a console application that handles arguments deeply, such as support for argument values.

To parse the arguments, you'll have to define a statically defined dictionary in a static class with a type of Dictionary<string, ArgumentInfo>, given that ArgumentInfo can be constructed with the following:

  • Argument: The argument name that users will have to write down

  • HelpDefinition: The description of the argument that will be shown in the help renderer

  • ArgArgumentInfo: An array of argument info instances that will modify its behavior

  • ArgumentBase: An argument executor instance that holds the actual code for the argument

  • Obsolete: Whether this argument is obsolete or not

Afterwards, you can use the ParseArguments() function somewhere in the main application code. You can find the relevant classes in the Terminaux.Shell.Arguments.Base namespace.

If you want to retain the behavior of Nitrocid KS 0.1.1 or earlier by considering every word as an argument, you can use the ParseArgumentsLegacy() function.

However, if you want to use the behavior of Nitrocid KS 0.1.2 or later by considering every word that matches one of the arguments as an argument, you can use the ParseArguments() function.

Switch Management

You can know more about switch management by clicking on the below button:

Special characters

If a command, such as wrap, is set to use the arguments string, you can escape special characters, as long as these characters are known. For example, if you want to pass a switch to a wrapped command, you can use the wrap command like this:

wrap help \-addon
Command Switches