Blame tipc/README

Packit d3f73b
DESIGN DECISIONS
Packit d3f73b
----------------
Packit d3f73b
Packit d3f73b
HELP
Packit d3f73b
~~~~
Packit d3f73b
--help or -h is used for help. We do not reserve the bare word "help", which
Packit d3f73b
for example the ip command does. Reserving a bare word like help quickly
Packit d3f73b
becomes cumbersome to handle in the code. It might be simple to handle
Packit d3f73b
when it's passed early in the command chain like "ip addr help". But when
Packit d3f73b
the user tries to pass "help" further down this requires manual checks and
Packit d3f73b
special treatment. For example, at the time of writing this tool, it's
Packit d3f73b
possible to create a vlan named "help" with the ip tool, but it's impossible
Packit d3f73b
to remove it, the command just shows help. This is an effect of treating
Packit d3f73b
bare words specially.
Packit d3f73b
Packit d3f73b
Help texts are not dynamically generated. That is, we do not pass datastructures
Packit d3f73b
like command list or option lists and print them dynamically. This is
Packit d3f73b
intentional. There is always that exception and when it comes to help texts
Packit d3f73b
these exceptions are normally neglected at the expence of usability.
Packit d3f73b
Packit d3f73b
KEY-VALUE
Packit d3f73b
~~~~~~~~~
Packit d3f73b
All options are key-values. There are both drawbacks and benefits to this.
Packit d3f73b
The main drawback is that it becomes more to write for the user and
Packit d3f73b
information might seem redundant. The main benefits is scalability and code
Packit d3f73b
simplification. Consistency is important.
Packit d3f73b
Packit d3f73b
Consider this.
Packit d3f73b
1. tipc link set priority PRIO link LINK
Packit d3f73b
2. tipc link set LINK priority PRIO
Packit d3f73b
Packit d3f73b
Link might seem redundant in (1). However, if the command should live for many
Packit d3f73b
years and be able to evolve example (2) limits the set command to only work on a
Packit d3f73b
single link with no ability to extend. As an example, lets say we introduce
Packit d3f73b
grouping on the kernel side.
Packit d3f73b
Packit d3f73b
1. tipc link set priority PRIO group GROUP
Packit d3f73b
2. tipc link set ??? priority PRIO group GROUP
Packit d3f73b
Packit d3f73b
2. breaks, we can't extend the command to cover a group.
Packit d3f73b
Packit d3f73b
PARSING
Packit d3f73b
~~~~~~~
Packit d3f73b
Commands are single words. As an example, all words in "tipc link list" are
Packit d3f73b
commands. Options are key-values that can be given in any order. In
Packit d3f73b
"tipc link set priority PRIO link LINK" "tipc link set" are commands while
Packit d3f73b
priority and link are options. Meaning that they can be given like
Packit d3f73b
"tipc link set link LINK priority PRIO".
Packit d3f73b
Packit d3f73b
Abbreviation matching works for both command and options. Meaning that
Packit d3f73b
"tipc link set priority PRIO link LINK" could be given as
Packit d3f73b
"tipc l s p PRIO l LINK" and "tipc link list" as "tipc l l".
Packit d3f73b
Packit d3f73b
MEMORY
Packit d3f73b
~~~~~~
Packit d3f73b
The tool strives to avoid allocating memory on the heap. Most (if not all)
Packit d3f73b
memory allocations are on the stack.
Packit d3f73b
Packit d3f73b
RETURNING
Packit d3f73b
~~~~~~~~~
Packit d3f73b
The tool could throw exit() deep down in functions but doing so always seems
Packit d3f73b
to limit the program in the long run. So we output the error and return an
Packit d3f73b
appropriate error code upon failure.