keba's Avatar keba 1
1 Asked
0 Answered
0 Best
1
No one has voted on this question yet :(
1 year, 6 months ago

Can you make a basic guide to designing a good Command Line User Interface?

I am currently doing a small serial project on the ATmega16, and I am trying to make a command line user interface. My input is a string with the desired command, like "LED -s 1". What is the best way of deciphering that? Can you make a basic guide to designing a good Command Line User Interface?
Sincerely, Keba
Separate topics with commas, or by pressing return. Use the delete or backspace key to edit or remove existing topics.

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

What is Your Answer?

0
0
0

6 Answers

1
opossum's Avatar
opossum | 1 year, 6 months ago
7
The C standard library has several functions useful for CLI parsing.

strtok() - Split string into tokens
strcmp(), strcmpi() - Compare strings
atoi() - Convert string to integer

So, split the command line into tokens with strtok(), compare the tokens to keywords with strcmp(), and when necessary convert numbers from ASCII to integer with atoi().

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
1
nuclearphoenix's Avatar
nuclearphoenix | 1 year, 6 months ago
1
There is a good part of the GNU C library called getopt. It already has a really simple api, and allows you to create a nice looking and easy to understand cli ui in a much cleaner way, than M$ guys suppose with both short (-s1) and long (--switch=1) types supported.
Also, there is a good lib called argtable. Also written in ANSI C, so it's very portable.
Chose whatever you like most. Both are cross platform and easy portable.

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
0
garyallen's Avatar
garyallen | 1 year, 6 months ago
15
There's a whole pile of freeware here that may do it for you:
http://software.informer.com/getfree-atmega-at-commands-bascom-avr/

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
0
com_kieffer's Avatar
com_kieffer | 1 year, 6 months ago
1
A good CLI should have short and long arguments for every switch, your '-s' switch would have the same meaning as '--do-something'. A could '--help' with a clear indications and descriptions of what the program does and how different switches affect it's behaviour is essential. To get an idea here's the the output of 'cat --help' in linux :

Usage: cat OPTION... FILE...
Concatenate FILE(s), or standard input, to standard output.

-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version output version information and exit

With no FILE, or when FILE is -, read standard input.

Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.

Report cat bugs to bug-coreutils@gnu.org
GNU coreutils home page:

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
0
jmlb's Avatar
jmlb | 1 year, 6 months ago
6
you could simply follow the Microsoft standard. Follow these rules and it would be easy to use your tool
http://technet.microsoft.com/en-us/library/ee156811.aspx

gnu has a set of standards too
http://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel
0
benhb's Avatar
benhb | 1 year, 6 months ago
1
I wrote an Arduino library for creating simple command line interfaces, it takes care of line parsing and calls relevant functions depending on the command. See the code linked off my page at http://us.cactii.net/~bb/ashfeeder/downloads.html

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

Report Abuse

Post Reply Cancel