1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
.. _example_module:
:orphan:
Example CLI Module
==================
::
"""
usage: slcli example [<command>] [<args>...] [options]
Example implementation of a CLI module
Available commands are:
parse parsing args example
pretty formatted print example
print print example
"""
from SoftLayer.CLI import (
CLIRunnable, Table, no_going_back, confirm)
class ExampleAction(CLIRunnable):
"""
usage: slcli example print [options]
Print example
"""
action = 'print'
def execute(self, args):
print "EXAMPLE!"
class ExamplePretty(CLIRunnable):
"""
usage: slcli example pretty [options]
Pretty output example
"""
action = 'pretty'
def execute(self, args):
# create a table with two columns: col1, col2
t = Table(['col1', 'col2'])
# align the data facing each other
# valid values are r, c, l for right, center, left
# note, these are suggestions based on the format chosen by the user
t.align['col1'] = 'r'
t.align['col2'] = 'l'
# add rows
t.add_row(['test', 'test'])
t.add_row(['test2', 'test2'])
return t
class ExampleArgs(CLIRunnable):
"""
usage: slcli example parse [--test] [--this=THIS|--that=THAT]
(--one|--two) [options]
Argument parsing example
Options:
--test Print different output
"""
action = 'parse'
options = ['confirm']
def execute(self, args):
if args.get('--test'):
print "Just testing, move along..."
else:
print "This is fo'realz!"
if args['--one']:
print 1
elif args['--two']:
print 2
if args.get('--this'):
print "I gots", args['--this']
if args.get('--that'):
print "you dont have", args['--that']
|