diff options
author | Doug Hellmann <doug.hellmann@dreamhost.com> | 2012-04-27 19:56:45 -0400 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@dreamhost.com> | 2012-04-27 19:56:45 -0400 |
commit | 556495e530c9cb2dc67300d1f199780e247921dc (patch) | |
tree | e7c63773f3001742dce82082efb13a52939326b5 /demoapp | |
parent | b8f3ad548d02eff5fe1b3c8d8515fab9db888204 (diff) | |
download | cliff-556495e530c9cb2dc67300d1f199780e247921dc.tar.gz |
add ShowOne base class for commands that need to show properties of an individual object
make the table formatter work as a single object formatter
update the docs for the new features
Diffstat (limited to 'demoapp')
-rw-r--r-- | demoapp/cliffdemo/show.py | 31 | ||||
-rw-r--r-- | demoapp/setup.py | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/demoapp/cliffdemo/show.py b/demoapp/cliffdemo/show.py new file mode 100644 index 0000000..54d98be --- /dev/null +++ b/demoapp/cliffdemo/show.py @@ -0,0 +1,31 @@ +import logging +import os + +from cliff.show import ShowOne + + +class File(ShowOne): + "Show details about a file" + + log = logging.getLogger(__name__) + + def get_parser(self, prog_name): + parser = super(File, self).get_parser(prog_name) + parser.add_argument('filename', nargs='?', default='.') + return parser + + def get_data(self, parsed_args): + stat_data = os.stat(parsed_args.filename) + columns = ('Name', + 'Size', + 'UID', + 'GID', + 'Modified Time', + ) + data = (parsed_args.filename, + stat_data.st_size, + stat_data.st_uid, + stat_data.st_gid, + stat_data.st_mtime, + ) + return (columns, data) diff --git a/demoapp/setup.py b/demoapp/setup.py index f24e792..83c957e 100644 --- a/demoapp/setup.py +++ b/demoapp/setup.py @@ -166,6 +166,7 @@ setup( 'two_part = cliffdemo.simple:Simple', 'error = cliffdemo.simple:Error', 'files = cliffdemo.list:Files', + 'file = cliffdemo.show:File', ], }, |