bsdphk / CLIkit

Python tool to make it easier to implement a CLI in C-code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is CLIkit
==============

This is the third generation of a facility I have used for many years,
which makes it easy to add a CLI interface to a C program.

CLI commands are described in a structured format:

	LEAF save_config INT {
		# Comment2
		DESC    "Save configuration to permanent storage"
		FUNC    save_config             # Comment3
	}

	LEAF load_config REAL {
		DESC    "Load configuration from permanent storage"
		FUNC    load_config
	}

	INSTANCE slot UINT {
		DESC    "Per slot configuration"
		FUNC    slot_instance

		LEAF timeout REAL {
			DESC "Timeout in seconds"
			FUNC do_slot_timeout
		}

		INSTANCE signal UINT {
			desc "Per signal configuration"
			func signal_instance

			LEAF frequency REAL {
				desc "Frequency in Hz"
				func ctl_frequency
			}
			LEAF shape ENUM { triangle ramp square sine } {
				desc "Curve shape"
				func ctl_shape
			}
			LEAF level REAL ENUM { Vpp Vrms dBm } {
				desc "Signal Level"
				func ctl_level
			}
		}
	}

The python script converts this into datastructures and code, which
handles all the tedious stuff like a "help" facility:

	./siggen
	Hello World
	help
	  save_config <INT>            Save configuration to permanent storage
	  load_config <REAL>           Load configuration from permanent storage
	  slot <UINT>:                 Per slot configuration
	    timeout <REAL>             Timeout in seconds
	    signal <UINT>:             Per signal configuration
	      frequency <REAL>         Frequency in Hz
	      shape <enum_30>          Curve shape
	      level <REAL> <enum_14>   Signal Level

All you have to do is write the functions you specified above to
actually do the stuff you want done.

What to Expect
==============

This newest iteration is a complete rewrite, for increased portability
and agility, but it is not complete yet, so caveat emptor.

One of the central ideas in this rewrite, is that everything is
contained in a single python script, so that should be all you need
to pull into your own software project.

While you wait for the 350 page leather-bound Nobel Literature Prize
winning manual to materialize, you may be able to clean some clues
by looking in .../SyntaxTests and .../Example*

Enjoy...

Poul-Henning

About

Python tool to make it easier to implement a CLI in C-code


Languages

Language:Python 77.5%Language:C 21.1%Language:Shell 1.0%Language:Objective-C 0.5%