Merge lp:~clint-fewbar/charm-tools/add-proper-help into lp:~charmers/charm-tools/trunk

Proposed by Clint Byrum
Status: Merged
Approved by: Juan L. Negron
Approved revision: 150
Merged at revision: 142
Proposed branch: lp:~clint-fewbar/charm-tools/add-proper-help
Merge into: lp:~charmers/charm-tools/trunk
Diff against target: 241 lines (+71/-33)
9 files modified
charm (+14/-15)
scripts/create (+15/-14)
scripts/get (+2/-2)
scripts/getall (+1/-0)
scripts/help (+11/-0)
scripts/list (+8/-0)
scripts/proof (+10/-2)
scripts/review-queue (+4/-0)
scripts/search (+6/-0)
To merge this branch: bzr merge lp:~clint-fewbar/charm-tools/add-proper-help
Reviewer Review Type Date Requested Status
Juan L. Negron (community) Approve
Review via email: mp+107118@code.launchpad.net

Description of the change

Adding proper --help and the new 'help' command to make accessing them easier. A little cleanup in the output of --help as well.

To post a comment you must log in.
Revision history for this message
Juan L. Negron (negronjl) wrote :

Looks good to me ... can you now do the same for juju itself :)

Approved.

-Juan

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm'
2--- charm 2011-09-23 18:23:55 +0000
3+++ charm 2012-05-23 20:56:24 +0000
4@@ -9,26 +9,25 @@
5
6 usage()
7 {
8- echo usage: $1 [ script_name ] >&2
9+ echo "usage: $1 [ --help|-h ] [ script_name ]" >&2
10 echo script choices are: >&2
11- exec ls $script_home >&2
12+ exec ls -1 $script_home|sed -e 's/^/ /' >&2
13 exit $2
14 }
15
16-options=$(getopt -o h -l help -- "$@")
17-if [ $? -ne 0 ]; then
18- usage $(basename $0) 1
19+# If the options seem invalid, pass thru to underlying scripts
20+if options=$(getopt -o h -l help -- "$@") ; then
21+ eval set -- "$options"
22+
23+ while true
24+ do
25+ case "$1" in
26+ -h|--help) usage $(basename $0) 0;;
27+ --) shift 1; break;;
28+ *) break;;
29+ esac
30+ done
31 fi
32-eval set -- "$options"
33-
34-while true
35-do
36- case "$1" in
37- -h|--help) usage $(basename $0) 0;;
38- --) shift 1; break;;
39- *) break;;
40- esac
41-done
42
43 script=${1:-""}
44
45
46=== modified file 'scripts/create'
47--- scripts/create 2012-05-14 22:42:35 +0000
48+++ scripts/create 2012-05-23 20:56:24 +0000
49@@ -27,6 +27,7 @@
50 import textwrap
51 import socket
52 import pwd
53+import argparse
54 from Cheetah.Template import Template
55 from stat import ST_MODE
56
57@@ -49,21 +50,21 @@
58 except ImportError:
59 get_maintainer = portable_get_maintainer
60
61-try:
62- package=sys.argv[1]
63-except:
64- print "Usage: create package_name [ charm_home_dir ]"
65- sys.exit(1)
66+parser = argparse.ArgumentParser()
67+parser.add_argument('charmname', help='Name of charm to create.')
68+parser.add_argument('charmhome', nargs='?',
69+ help='Dir to create charm in. Defaults to CHARM_HOME env var or PWD')
70+args = parser.parse_args()
71
72-try:
73- charm_home = sys.argv[2]
74-except:
75+if args.charmhome:
76+ charm_home = args.charmhome
77+else:
78 charm_home = os.getenv('CHARM_HOME','.')
79
80 home = path.abspath(path.join(path.dirname(sys.argv[0]), '..'))
81 template_dir = path.join(home, 'templates')
82-output_dir = path.join(charm_home, package)
83-print "Generating template for " + package + " from templates in " + template_dir
84+output_dir = path.join(charm_home, args.charmname)
85+print "Generating template for " + args.charmname + " from templates in " + template_dir
86 print "Charm will be stored in " + output_dir
87
88 if path.exists(output_dir):
89@@ -72,18 +73,18 @@
90
91 shutil.copytree(path.join(template_dir,'charm'), output_dir)
92
93-v={'package': package,
94+v={'package': args.charmname,
95 'maintainer': '%s <%s>' % get_maintainer() }
96
97 try:
98 c = apt.Cache()
99 c.open()
100- p = c[package]
101- print "Found " + package + " package in apt cache, as a result charm contents have been pre-populated based on package metadata."
102+ p = c[args.charmname]
103+ print "Found " + args.charmname + " package in apt cache, as a result charm contents have been pre-populated based on package metadata."
104 v['summary'] = p.summary
105 v['description'] = textwrap.fill(p.description,width=72, subsequent_indent=' ')
106 except:
107- print "Failed to find " + package + " in apt cache, creating an empty charm instead."
108+ print "Failed to find " + args.charmname + " in apt cache, creating an empty charm instead."
109 v['summary'] = '<Fill in summary here>'
110 v['description'] = '<Multi-line description here>'
111
112
113=== modified file 'scripts/get'
114--- scripts/get 2012-01-19 20:28:23 +0000
115+++ scripts/get 2012-05-23 20:56:24 +0000
116@@ -1,8 +1,8 @@
117 #!/bin/bash
118
119-if [ -z "$1" ] ; then
120+if [ -z "$1" -o "$1" = "--help" ] ; then
121 echo "Retrieves official charm branches from https://launchpad.net/charm" >&2
122- echo "usage: charm get name_of_charm [ local_charm_repo ]" >&2
123+ echo "usage: charm get [ --help ] name_of_charm [ local_charm_repo ]" >&2
124 exit 1
125 fi
126
127
128=== modified file 'scripts/getall'
129--- scripts/getall 2011-09-23 18:23:55 +0000
130+++ scripts/getall 2012-05-23 20:56:24 +0000
131@@ -4,6 +4,7 @@
132 usage()
133 {
134 echo "usage: getall path_to_charms" >&2
135+ echo "retrieves all charms from launchpad using mr and bzr"
136 exit $1
137 }
138
139
140=== added file 'scripts/help'
141--- scripts/help 1970-01-01 00:00:00 +0000
142+++ scripts/help 2012-05-23 20:56:24 +0000
143@@ -0,0 +1,11 @@
144+#!/bin/sh
145+usage() {
146+ echo usage: `basename $0` command_name
147+ echo shows help for the given command.
148+}
149+if [ "$1" = "--help" ] ; then
150+ usage
151+ exit 0
152+fi
153+home=`dirname $0`
154+$home/$1 --help
155
156=== modified file 'scripts/list'
157--- scripts/list 2012-01-19 20:28:23 +0000
158+++ scripts/list 2012-05-23 20:56:24 +0000
159@@ -1,6 +1,14 @@
160 #!/usr/bin/env python
161
162 from launchpadlib.launchpad import Launchpad
163+import sys
164+
165+if len(sys.argv) > 1:
166+ print('usage: list [ --help ]')
167+ if sys.argv[1] == '--help':
168+ sys.exit(0)
169+ else:
170+ sys.exit(1)
171
172 lp = Launchpad.login_anonymously('charm-tools', 'production', version='devel')
173 charm = lp.distributions['charms']
174
175=== modified file 'scripts/proof'
176--- scripts/proof 2012-05-15 23:33:54 +0000
177+++ scripts/proof 2012-05-23 20:56:24 +0000
178@@ -25,6 +25,7 @@
179 import yaml
180 import re
181 import email.utils
182+import argparse
183
184 exit_code = 0
185
186@@ -47,8 +48,15 @@
187 """ Ignorable but sometimes useful """
188 print "I: " + msg
189
190-if len(sys.argv) >= 2:
191- charm_name = sys.argv[1]
192+
193+parser = argparse.ArgumentParser(
194+ description='Performs static analysis on charms')
195+parser.add_argument('charm_name', nargs='?',
196+ help='path of charm dir to check. Defaults to PWD')
197+args = parser.parse_args()
198+
199+if args.charm_name:
200+ charm_name = args.charm_name
201 else:
202 charm_name = os.getcwd()
203
204
205=== modified file 'scripts/review-queue'
206--- scripts/review-queue 2012-05-23 17:38:12 +0000
207+++ scripts/review-queue 2012-05-23 20:56:24 +0000
208@@ -4,6 +4,7 @@
209 from operator import itemgetter
210 import datetime
211 import itertools
212+import argparse
213
214 def calculate_age(from_date = None):
215 if not from_date:
216@@ -121,6 +122,9 @@
217 return(sorted(queue, key=lambda k: k['date_created']))
218
219 def main():
220+ parser = argparse.ArgumentParser(
221+ description="Shows items needing the attention of ~charmers")
222+ parser.parse_args()
223 review_queue = charm_review_queue()
224 keys = ['date_created', 'age', 'summary', 'item', 'status' ]
225 headers = ['Date Created', 'Age', 'Summary', 'Item', 'Status']
226
227=== modified file 'scripts/search'
228--- scripts/search 2012-01-11 11:26:08 +0000
229+++ scripts/search 2012-05-23 20:56:24 +0000
230@@ -1,5 +1,11 @@
231 #!/bin/bash
232
233+if [ "$1" = "--help" ] ; then
234+ echo "usage: `basename $0` grep_pattern"
235+ echo "greps the list of charms"
236+ exit 0
237+fi
238+
239 [ -z "${1}" ] && echo "Search parameter required" && exit 1
240
241 charm list | grep "${1}"

Subscribers

People subscribed via source and target branches