Controlling Terminal Output

The yangcli-pro and yp-shell programs support terminal output filtering and paginated output. Pipe commands allow the line-by-line terminal output to be filtered, formatted, or redirected.

  • Pipe Commands: filter show command output and server response output

  • Pagination: pause output after each page, allowing the user to continue or quit the output

  • Display Mode: Specifies the display format (e.g., plain, cli, XML, JSON)

Pipe Commands

Pipe commands are used to control the terminal output

  • Pipe Commands: filter show command output and server response output

    • begin: start output after this pattern matches

    • include: include lines that match this pattern

    • exclude: exclude lines that match this pattern

    • redirect: send output to a text file instead of the screen

    • display: format the output in XML, JSON, CLI, or plain format

Usage Notes:

  • The pipe commands can be combined.

  • The “include” and “exclude” commands can be specified multiple times

  • The “redirect” filespec is relative to the current working directory

  • The “display” parameter is used to over-ride the current $$display-mode variable setting.

Examples:

The “show fan” command is an external command from the example-show.yang module.

It is not a real command within yangcli-pro.

The full output of the command is shown first, without any pipe commands:

> show fan 1 --full

Report for Fan 1
  put fan status here...
  put more fan status here...
  put even more fan status here...

The “begin” command: this is case-sensitive so the first “fan” matches, not “Fan”

> show fan 1 --full | begin fan

  put fan status here...
  put more fan status here...
  put even more fan status here...

>

The “include” command:

> show fan 1 --full | include more
  put more fan status here...
  put even more fan status here…

>

The “exclude” command:

> show fan 1 --full | exclude more

Report for Fan 1
  put fan status here...

>

The “display” command:

andy@localhost> sget /system/uname|display json

Filling container /system/uname:
RPC Data Reply 11 for session 3 [default]:
{
  "yuma-netconf:rpc-reply": {
    "yuma-netconf:data": {
      "yuma-system:system": {
        "uname": {
          "sysname":"Linux",
          "release":"4.4.0-104-generic",
          "version":"#127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017",
          "machine":"x86_64",
          "nodename":"andy-2i7"
        }
      }
    }
  }
}

andy@localhost>

The “display” and “redirect” commands combined:

andy@localhost> sget /system|redirect ~/test1.json display json

Filling container /system:
andy@localhost>

pipe YANG Definition

container pipe {
  ncx:abstract;
  ncx:hidden;

  description
    "Pipe command sub-commands.
     The 'begin', 'include', and 'exclude' parameters are used
     to filter command output. If these parameters contain
     any pattern meta-characters, then they will be treated
     as a YANG pattern string.  If a plain string is found
     instead, then this string must be found in the line
     to be considered a match.

     Each output line is processed in the following manner:
       1) if begin set and not triggered yet, then test
          the line. If a match then disable this step
          for future lines and continue testing output,
          else skip this line.
       2) check each exclude parameter. If any match then
          skip this line.
       3) check each include parameter. If any match then
          include this line, else skip this line.
       4) include the line in the output.

     If the 'redirect' parameter is present then the filtered
     output will be sent to a file instead of the session.

     If the 'display' parameter is present then the specified
     display format will be used for the output and the
     filtering format. By default, the current display-mode
     is used for both filtering and output formats.";

  leaf begin {
    type string;
    description
      "Specifies the pipe begin line pattern.";
  }

  leaf-list include {
    type string;
    description
      "Specifies a pipe include line pattern.
       Multiple parameters are treated as a logical-OR
       expression.";
  }

  leaf-list exclude {
    type string;
    description
      "Specifies a pipe exclude line pattern.
       Multiple parameters are treated as a logical-OR
       expression.";
  }

  leaf redirect {
    type string;
    description
      "Specifies the pipe output redirect filespec.
       If this filespec already exists then output
       will be appended to the file.";
  }

  leaf display {
    type enumeration {
      enum xml {
        description "Display output in XML";
      }
      enum json {
        description "Display output in JSON";
      }
      enum curmode {
        description
          "Display output is the current $$display-mode";
      }
      enum plain {
        description "Display output in plain format";
      }
      enum cli {
        description "Display output in CLI format";
      }
    }
    default "curmode";
    description
      "Specifies the pipe output display format.";
  }
}

Pagination

  • Pagination: pause output after each page, allowing the user to continue or quit the output

    • --More-- prompt displayed at each pause

    • terminal length command controls number of lines printed per page

    • $$term-length variable also controls number of lines printed per page

    • space bar prints next page, return prints next line, ‘q’ to quit output

leaf term-length {
  description
    "Specifies the length of the terminal to use for page
     mode output with the -More- prompt. This parameter
     is ignored in batch mode. It is only used if the
     output session is operating in interactive mode.

     If the value 0 is used then the 'More' prompt will
     be disabled. Otherwise this value represents the
     number of lines to output for each screen in pagination
     output mode.";
  type uint16 {
    range "0 .. 511";
  }
  default 0;
}

Example using pagination and pipe commands together:

andy@localhost> term length 10

OK

andy@localhost> sget /system/uname|display json

Filling container /system/uname:
RPC Data Reply 12 for session 3 [default]:
{
  "yuma-netconf:rpc-reply": {
    "yuma-netconf:data": {
      "yuma-system:system": {
        "uname": {
          "sysname":"Linux",
          "release":"4.4.0-104-generic",
          "version":"#127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017",

  --More--

Examples setting terminal length:

> $$term-length = 20
> term length 20

Display Mode

The display mode controls the output format used to display YANG data:

  • Not all commands use YANG data so the display mode does not affect all commands.

  • Some show commands for example use plain text output only.

  • Commands that return “OK” or some error message are not affected by the display mode.

  • Commands that return server data and display the response support all display modes

  • Setting the Display Mode:

    • $$display-mode variable controls the output display format

    • The pipe command “display” overrides the $$display-mode setting for the current command

  • Displaying the current display mode:

> show var display-mode
display-mode cli

Display Mode YANG Definition

leaf display-mode {
  description
     "Controls how values are displayed during output
      to STDOUT or a log file.";
   type enumeration {
     enum plain {
       description
           "Plain identifier without any prefix format.";
     }
     enum prefix {
       description
          "Plain text with XML prefix added format.";
     }
     enum module {
       description
          "Plain text with module name as prefix added format.";
     }
     enum xml {
       description
          "XML format.";
     }
     enum xml-nons {
       description
          "XML format, but no namespace (xmlns) attributes
           will be generated.";
     }
     enum json {
       description
          "JSON format.";
     }
     enum cli {
       description
          "CLI format.";
     }
  }
  default plain;
}

Plain Mode Example:

andy@localhost> sget /system/uname

Filling container /system/uname:
RPC Data Reply 14 for session 3 [default]:

rpc-reply {
  data {
    system {
      uname {
        sysname Linux
        release 4.4.0-104-generic
        version '#127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017'
        machine x86_64
        nodename andy-2i7
      }
    }
  }
}

andy@localhost>

CLI Mode example:

andy@localhost> sget /system/uname

Filling container /system/uname:
RPC Data Reply 15 for session 3 [default]:

rpc-reply
  data
    system
      uname
        sysname Linux
        release 4.4.0-104-generic
        version '#127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017'
        machine x86_64
        nodename andy-2i7

andy@localhost>