Monday, May 14, 2012

GUI for Constructing Command Line - Concepture Design

The purpose for this article is to propose a conceptual design for a generalized GUI tool that can help user constructing a valid command for command line interface. The design is to be general and capable to handle as many command line specification as possible. In the process we also like to be able to enforce syntax rules as much as possible.

As I work through the idea and prototype, I will continue to update this article.

The design begins with the data structure.

(20120604)
After re-examining the problem, I am settling to a data structure that would not be able to represent faithful implementation of all possible command line construct. What this mean is that we may not be able to parse a command line correctly based on our data structure for certain command. This, however, does not preclude us from produce legitimate command line. A category of command line construct that could not be faithfully represented by this data structure design is those commands that allows the required options to be presented in random orders. Our data structure will put those options in an order and, therefore, won't be able be used to parse command line that presents those option in different order, which were allowed by the real command line interpreter.

Child Node Type:
(o) - Child nodes are in (o)rder and are defaulted to be required.
(-) - Child nodes are all optional. Actions are needed to include them in the command line.
(1) - Exactly 1 child node is need to presented in the command line.
(0) - No child node. Optional text value and default flag or required keyword
(r) - The child node can be repeated as many times as possible.

Common attributes for nodes:
  Slctd - selected
  Dscrptn -
  Syntx -
    SyntxLtrl
    SyntxPrs
    SyntxVldtn
  Vl - value
  VlRE - for checking Vl
  Optns - No value, default ...

Possible construct:
copy -Src SrcFl -Dest DestFl -Ascii -LF
  copy (o)
    -Src FlNm (0)
    -Dest FlNm (0)
    ways of copy (1)
      -Ascii (1)
        -LF (0)
        -CRLF(0)
      -Binary (0)

*The above structure may not faithfully represent the copy command if the copy command allowed this construct:
  copy -Dest DestFl -Src SrcFl -Ascii -LF

<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. -->
<Nd SyntxKy="Copy" >
  <SyntxLtrl>copy</SyntxLtrl>
  <Dscrptn>copy a file</Dscrptn>
  <Chld Typ="o">
    <Nd SyntxKy="-Src" >
      <Dscrptn>file to be copied</Dscrptn>
      <SyntxLtrl>-Src </SyntxLtrl>
      <Vl></Vl>
      <VlRE></VlRE>
    </Nd>
    <Nd SyntxKy="-Dest" >
      <Dscrptn>file to be copy to</Dscrptn>
      <SyntxLtrl>-Dest </SyntxLtrl>
      <Vl></Vl>
      <VlRE></VlRE>
    </Nd>
    <Nd SyntxKy="ways of copy" >
      <Dscrptn>file type</Dscrptn>
      <SyntxLtrl></SyntxLtrl>
      <Chld Typ="1">
        <Nd SyntxKy="Ascii" >
          <Dscrptn>ASCII</Dscrptn>
          <SyntxLtrl>-Ascii </SyntxLtrl>
          <Chld Typ="1">
            <Nd SyntxKy="LF" >
              <Dscrptn>Convert line break to LF</Dscrptn>
              <SyntxLtrl>-LF </SyntxLtrl>
            </Nd>
            <Nd SyntxKy="CRLF" >
              <Dscrptn>Convert line break to CRLF</Dscrptn>
              <SyntxLtrl>-CRLF </SyntxLtrl>
            </Nd>
          </Chld>
        </Nd>
        <Nd SyntxKy="Binary" >
          <Dscrptn>byte by byte/literal copy</Dscrptn>
          <SyntxLtrl>-Binary</SyntxLtrl>
        </Nd>
      </Chld>
    </Nd>
  </Chld>
</Nd>

GUI design:
(-) - checkbox
(1) - radio button
(o) - linked control group:
    An ordered node syntax:
      (o) (-) (t) Optn1
              (t) Optn2
              (t) Optn3
              (t) Optn4
          (1) (t) OptnA
              (t) OptnB
    Can be expressed in a graph like:
      +---------------------+
      |         +--+        |
      |   Optn1 |  |o OptnA |
      | x Optn2 |  |o OptnB |
      |   Optn3 |  +--------+
      |   Optn4 |
      +---------+

A possible description in XML can be: