From Gary Oberbunner's technique, I came up with the following wrapper functions. They can be used to build the help text automatically from all of your Alias() commands:
1 from SCons.Script.SConscript import SConsEnvironment
2
3 #-- ------------------
4 #-- jDataClass holds data for the helper functions
5 class jDataClass:
6 mHelpText = {}
7 mHelpTextHead = []
8 mHelpTextTail = []
9 SConsEnvironment.jData = jDataClass()
10 #-- ------------------
11 #-- wraps Alias to put the alias name in the help text
12 def jAlias(self, aliasname, tgt, helptext=None):
13 thealias = self.Alias(aliasname, tgt)
14 lcaliasname = aliasname.lower()
15 if helptext is None:
16 if not self.jData.mHelpText.has_key(lcaliasname):
17 self.jData.mHelpText[lcaliasname] = '???'
18 else:
19 self.jData.mHelpText[lcaliasname] = helptext
20 return thealias
21 SConsEnvironment.jAlias = jAlias
22 #-- ------------------
23 #-- adds a line of text to the help heading
24 def jHelpHead(self, msg):
25 self.jData.mHelpTextHead.append(msg);
26 SConsEnvironment.jHelpHead = jHelpHead
27 #-- ------------------
28 #-- adds a line of text to the help footing
29 def jHelpFoot(self, msg):
30 self.jData.mHelpTextTail.append(msg);
31 SConsEnvironment.jHelpFoot = jHelpFoot
32 #-- ------------------
33 #-- generates the help
34 def jGenHelp(self):
35 tmp = []
36 tmp.extend(self.jData.mHelpTextHead)
37 keys = self.jData.mHelpText.keys()
38 keys.sort()
39 maxlen = 0
40 for a in keys:
41 if len(a) > maxlen: maxlen = len(a)
42 for a in keys:
43 s = ' %-*s : %s' % (maxlen, a, self.jData.mHelpText[a])
44 tmp.append(s)
45 tmp.extend(self.jData.mHelpTextTail)
46 self.Help("\n".join(tmp))
47 SConsEnvironment.jGenHelp = jGenHelp
48 #-- ------------------
49 #-- adds upper/lower case of alias names for a target
50 def jSetAliases(self, projname, tgt):
51 self.jAlias(projname, tgt)
52 self.jAlias(projname.lower(), tgt, "compile " + projname)
53 SConsEnvironment.jSetAliases = jSetAliases
54
55 #SConsEnvironment.dev = Dev()
56
57 env = Environment()
58 env.jHelpHead("First line of Help...")
59 env.jHelpFoot("Last line of Help...")
60
61 #use jAlias like Alias() except that you can add an optional bit of help text to it
62 env.jAlias('prepare_downloads', prepalias, "prepare 'downloads' html page")
63
64 .... other stuff here ...
65
66 #--- this statement must be the last in the file
67 env.jGenHelp()
when you do scons -h you get the help for all of your aliases automatically:
scons: Reading SConscript files ... **** Compiling in debug mode... scons: done reading SConscript files. First line of Help... prepare_downloads : prepare 'downloads' html page Last line of Help... Use scons -H for help about command-line options.
Comment
This is really useful, and I'd vote for such functionality being added to the core Alias function. However, what happens if kAlias is called twice for the same target, i.e. adding targets to an alias, but the second call doesn't have any help text. Doesn't it overwrite the existing help text?
