Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Command Line Interface Pages parser

Command Line Interface Pages parser.

Prerequisites

Installation 😄

Download installer as a temporary file and execute commands to download and install parser with its man page:

make -f <(wget -O - https://raw.githubusercontent.com/command-line-interface-pages/v2-tooling/main/clip-parse/makefile 2> /dev/null) remote-install

Download installer as a installer file and execute commands to download and install parser with its man page:

wget -O installer https://raw.githubusercontent.com/command-line-interface-pages/v2-tooling/main/clip-parse/makefile
make -f installer remote-install

ℹ️ Note: prefer the second way to install if you want to be able to easily uninstall parser with its man page.

Uninstallation 😞

Execute commands to uninstall parser with its man page:

make -f installer uninstall

Examples 📚

Input Command Line Interface Page:

# [

> Check file types and compare values
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false
> More information: https://www.gnu.org/software/bash/manual/bash.html#index-test

- Test if a specific variable is (equal|not equal) to a string:

`[ "{string $variable: $foo}" {string operator: ==|string operator !=} "{string string: Hello world!}" ]`

- Test if a specific variable is ([eq]ual|[n]ot [e]qual|[g]reater [t]han|[l]ess [t]han|[g]reater than or [e]qual|[l]ess than or [e]qual) to a number:

`[ "{string $variable: $foo}" {string operator: -eq|string operator: -ne|string operator: -gt|string operator: -lt|string operator: -ge|string operator: -le} {string number: 1} ]`

- Test if a specific variable has (an empty|a [n]on-empty) value:

`[ {string operator: -z|string operator: -n} "{string $variable: $foo}" ]`

- Test if a specific [f]ile exists:

`[ -f {/?file some: ~/.bashrc} ]`

- Test if a specific [d]irectory exists:

`[ -d {/?directory some: images} ]`

- Test if a specific file or directory [e]xists:

`[ -e {/?path some: ~/.bashrc} ]`

Let's say we put it in $page variable.

Basic usage

  • question How to get a page header?
    💡 answer

    parser__header_prettified "$page"

    🏁 output

    [
  • question How to get a page description?
    💡 answer

    parser_summary__description_prettified "$page"

    🏁 output

    Check file types and compare values
    Returns 0 if the condition evaluates to true, 1 if it evaluates to false
  • question How to get an example description?
    💡 answer

    parser_examples__description_prettified_at "$page" 0

    🏁 output

    Test if a specific variable is (equal|not equal) to a string
  • question How to get an example code?
    💡 answer

    parser_examples__code_prettified_at "$page" 0

    🏁 output

    [ "{string $variable: $foo}" {string operator: ==|string operator: !=} "{string string: Hello world!}" ]
  • question How to get tokens for alternatives?
    💡 answer

    parser_examples__description_alternative_tokens_at "$page" 0

    🏁 output

    LITERAL
    Test if a specific variable is 
    CONSTRUCT
    equal|not equal
    LITERAL
     to a string
  • question How to get tokens for mnemonics?
    💡 answer

    parser_examples__description_mnemonic_tokens_at "$page" 2

    🏁 output

    LITERAL
    Test if a specific variable has (an empty|a 
    CONSTRUCT
    n
    LITERAL
    on-empty) value
  • question How to get tokens for placeholders?
    💡 answer

    parser_examples__code_placeholder_tokens_at "$page" 0

    🏁 output

    LITERAL
    [ "
    CONSTRUCT
    string $variable: $foo
    LITERAL
    " 
    CONSTRUCT
    string operator: ==|string operator !=
    LITERAL
     "
    CONSTRUCT
    string string: Hello world!
    LITERAL
    " ]

Advanced usage

  • question How to get a token count?
    💡 answer

    parser_tokens__count "$(parser_examples__description_alternative_tokens_at "$page" 0)"

    🏁 output

    3
  • question How to get a token value?
    💡 answer

    parser_tokens__value "$(parser_examples__description_alternative_tokens_at "$page" 0)" 0

    🏁 output

    Test if a specific variable is 
  • question How to get a token type?
    💡 answer

    parser_tokens__type "$(parser_examples__description_alternative_tokens_at "$page" 0)" 0

    🏁 output

    LITERAL
  • question How to get pieces (parts listed via unescaped |) for an alternative?
    💡 answer

    value="$(parser_tokens__value "$(parser_examples__description_alternative_tokens_at "$page" 0)" 1)"
    parser_examples__description_alternative_token_pieces "$value"

    🏁 output

    CONSTRUCT
    equal
    CONSTRUCT
    not equal
  • question How to get pieces (parts listed via unescaped |) for a placeholder?
    💡 answer

    value="$(parser_tokens__value "$(parser_examples__code_placeholder_tokens_at "$page" 0)" 3)"
    parser_examples__code_placeholder_token_pieces "$value"

    🏁 output

    CONSTRUCT
    string operator: ==
    CONSTRUCT
    string operator: !=
  • question How to get a placeholder piece type?
    💡 answer

    value="$(parser_tokens__value "$(parser_examples__code_placeholder_tokens_at "$page" 0)" 1)"
    parser_examples__code_placeholder_piece_type "$value"

    🏁 output

    string
  • question How to get a lowest range boundary?
    💡 answer

    parser_ranges__from_or_default "2..4"

    🏁 output

    2
  • question How to get a rendered placeholder piece?
    💡 answer

    value="$(parser_tokens__value "$(parser_examples__code_placeholder_tokens_at "$page" 0)" 1)"
    parser_converters__code_placeholder_piece_to_rendered "$value" # as this placeholder contains just one piece this code works

    🏁 output

    "$variable"