summaryrefslogtreecommitdiff
path: root/demoapp
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-27 19:56:45 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-27 19:56:45 -0400
commit556495e530c9cb2dc67300d1f199780e247921dc (patch)
treee7c63773f3001742dce82082efb13a52939326b5 /demoapp
parentb8f3ad548d02eff5fe1b3c8d8515fab9db888204 (diff)
downloadcliff-tablib-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.py31
-rw-r--r--demoapp/setup.py1
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',
],
},