File: TagcollParser.h

package info (click to toggle)
tagcoll2 2.0.11-1.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,520 kB
  • ctags: 1,522
  • sloc: sh: 8,977; cpp: 6,242; makefile: 187; lex: 54; yacc: 27
file content (308 lines) | stat: -rw-r--r-- 11,064 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#ifndef TAGCOLL_OPTIONS_H
#define TAGCOLL_OPTIONS_H

/*
 * Commandline parser for tagcoll
 *
 * Copyright (C) 2003,2004,2005,2006  Enrico Zini
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <wibble/commandline/parser.h>

namespace wibble {
namespace commandline {

class TagcollParser : public StandardParserWithMandatoryCommand
{
public:
	// Input
	ExistingFileOption* in_derived;
	ExistingFileOption* in_extimpl;
	ExistingFileOption* in_rename;
	ExistingFileOption* in_patch;
	BoolOption* in_rmunfaceted;
	StringOption* in_rmtags;

	// Output
	BoolOption* out_group;
	BoolOption* out_redundant;
	BoolOption* out_itemsOnly;
	BoolOption* out_count;

	// Hierarchy
	IntOption* hie_flatten;
	IntOption* hie_filter;

	// Other options
	StringOption* misc_untaggedTag;
	IntOption* misc_distance;
	BoolOption* misc_invert;
	BoolOption* misc_quiet;

	// Commands
	Engine* copy;
	Engine* reverse;
	Engine* diff;
	Engine* related;
	Engine* implications;
	Engine* hierarchy;
	Engine* cleanhierarchy;
	Engine* dischierarchy;
	Engine* findspecials;
	Engine* grep;
	Engine* test;

protected:
	// Create the input options group
	OptionGroup* inputOptions()
	{
		OptionGroup* group = createGroup("Options controlling transformations of input data");
		in_derived = group->add<ExistingFileOption>(
					"derived-tags-from", 0, "derived", ""
					"expand derived tags using the given list");
		in_extimpl = group->add<ExistingFileOption>(
					"extimpl", 0, "implications-from", ""
					"use an external list of implications");
		in_rename = group->add<ExistingFileOption>(
					"rename", 0, "rename-from", ""
					"rename tags using the given mapping list");
		in_patch = group->add<ExistingFileOption>(
					"patch", 'p', "patch-with", ""
					"apply patches from the given tag patch file");
		in_patch->addAlias("patch");
		in_rmunfaceted	= group->add<BoolOption>(
					"rmunfaceted", 0, "remove-unfaceted", ""
					"while parsing, remove all tags with no facet part");
		in_rmtags		= group->add<StringOption>(
					"rmtags", 0, "remove-tags", "<expression>",
					"while parsing, remove all tags matching the given tag expression");
		return group;
	}

	// Create the output options group
	OptionGroup* outputOptions()
	{
		OptionGroup* group = createGroup("Options controlling transformations of output data");
		out_group	  = group->add<BoolOption>("group", 'g', "group", "",
						"group items with the same tagset in the output collection");
		out_group->addAlias("group-items");
		out_redundant = group->add<BoolOption>("redundant", 0, "redundant", "",
						"when implications are provided, expand them explicitly in the output");
		out_itemsOnly = group->add<BoolOption>("items", 'i', "items", "",
						"output only the names of the items, without the tags");
		out_count = group->add<BoolOption>("count", 'c', "count", "",
						"output the count of tags instead of the tags");
		return group;
	}

	// Create the hierarchy options group
	OptionGroup* hierarchyOptions()
	{
		OptionGroup* group = createGroup("Options controlling generation of tag hierarchies");
		hie_flatten = group->add<IntOption>("flatten", 0, "flatten-threshold", "",
						"set the number of total items below which a branch is flattened when "
						"using the \"hierarchy\" command (defaults to 0, meaning "
						"\"don't flatten\")");
		hie_filter =  group->add<IntOption>("filter", 'f', "filter", "",
						"filter out the tags with cardinality less than the given value "
						"(defaults to not filter; currently only works when building hierarchies)");
		return group;
	}

public:

	TagcollParser()
		: StandardParserWithMandatoryCommand("tagcoll", VERSION, 1, "enrico@enricozini.org")
	{
		usage = "<command> [options and arguments]";
		description = "Perform various operations on a tagged collection";
		
		OptionGroup* inputOpts = inputOptions();
		OptionGroup* outputOpts = outputOptions();
		OptionGroup* hierarchyOpts = hierarchyOptions();


		// 'copy' command
		copy = addEngine("copy", "[files...]",
				"output the collection",
				"Output the normalized collection on standard output, applying transformations "
				"if requested.  This is the default action if no other switches are provided.  "
				"A normalized collection is a collection in which an item appears in just one "
				"line.");
		copy->aliases.push_back("cat");
		copy->add(inputOpts);
		copy->add(outputOpts);

		// 'reverse' command
		reverse = addEngine("reverse", "[files...]",
				"\"reverse\" the collection, outputting one with items associated to tags",
				"Output the inbound collection \"reversed\" from the tags point of view, that is, "
				"associating to each tag the list of items associated to it in the input.\n"
				"The --untagged-tag switch can be used to provide a name to which untagged "
				"items will be associated in the output.");
		misc_untaggedTag = reverse->add<StringOption>("untagged-tag", 0, "untagged-tag", "<tag>",
				"set item name to use for associating untagged items when using the \"reverse\" "
				"command.  If not specified, untagged items are not included in the output");
		reverse->add(inputOpts);	
		reverse->add(outputOpts);	

		// 'diff' command
		diff = addEngine("diff", "<file1> <file2>",
				"output a tag patch file with the differences between two files",
				"Output a tag patch file with the differences between two files (requires two "
				"file arguments).\n"
				"The output tag patch file can then be applied when reading a collection with "
				"the --patch-with option.");
	
		// 'related' command
		related = addEngine("related", "<item> [files...]",
				"print a list of items related to the given one",
				"Output a list of the items that are related to the given item or list of items.  "
				"If more than one items are to be specified, separate them with commas.\n"
				"The --distance option can be used to control how closely related the output "
				"items shold be from the item(s) specified.");
		related->examples = "tagcoll related mutt,mozilla-browser -";
		misc_distance = related->add<IntOption>("distance", 'd', "distance", "",
				"set the maximum distance to use for the \"related\" command (defaults to 0)");
		related->add(inputOpts);

		// 'implications' command
		implications = addEngine("implications", "[files...]",
				"compute a list of tag implications",
				"Output a list of all implicit implications between tags contained in the "
				"hierarchy.  Implication is defined such that tag A implies tag B if every item "
				"tagged with A is also tagged with B.\n"
				"Implications can be used to discover implicit hierarchical relationships "
				"between tags.\n"
				"The output is one line per tag, with just tags that have implications, with the "
				"name of the package, a colon and a comma-separated list of all implied tags.");
		implications->examples =
				"C:devel,languages\n"
				"ada:devel,languages\n"
				"apachemodules:net,servers,web\n"
				"browsers:net,web\n";
		implications->add(inputOpts);

		// 'hierarchy' command
		hierarchy = addEngine("hierarchy", "[files...]",
				"build a smart hierarchy with the collection data",
				"Organize the collection in an intuitively navigable hierarchy.  The "
				"output is one line per package, with the package name prepended by the "
				"path to the item in the hierarchy.\n"
				"A detailed description of the hierarchy generation algorithm is found in the "
				"tagbk-draft.pdf draft paper available in this package; if you want to "
				"understand what are the goals of the algorithm and how it works, please give it "
				"a read.");
		hierarchy->examples =
				"/net/clients/mail: mutt\n"
				"/net/filters/mail: procmail\n";
		hierarchy->add(inputOpts);
		hierarchy->add(hierarchyOpts);

		// 'cleanhierarchy' command
		cleanhierarchy = addEngine("cleanhierarchy", "[files...]",
				"build a cleaned smart hierarchy with the collection data",
				"Like hiearchy, but in every node it merges tags which are attached to the "
				"same set of items.");
		cleanhierarchy->add(inputOpts);
		cleanhierarchy->add(hierarchyOpts);

		// 'cleanhierarchy' command
		dischierarchy = addEngine("dischierarchy", "[files...]",
				"build a hierarchy using discriminance properties of tags",
				"The tree starts with an empty tag set, and branches with the most "
				"discriminant tags.");
		dischierarchy->add(inputOpts);
		dischierarchy->add(hierarchyOpts);

		// 'findspecials' command
		findspecials = addEngine("findspecials", "[files...]",
				"generate a smart hierarchy and print, for each toplevel tag, "
				"what are the items that make it toplevel instead of going below "
				"another tag");
		findspecials->add(inputOpts);
		findspecials->add(hierarchyOpts);

		// 'grep' group
		grep = addEngine("grep", "<expression> [files...]",
			"output the collection of tags that match the given tag expression");
		grep->add(inputOpts);
		grep->add(outputOpts);
		misc_invert = grep->add<BoolOption>("invert", 'v', "invert-match", "",
				"invert the sense of matching, to select non-matching lines");
		misc_quiet = grep->add<BoolOption>("quiet", 'q', "quiet", "",
				"do not write anything to standard output, but exit with 0 if any match is found");

		// 'test' group
		test = addEngine("test", "[files...]",
			"perform internal tests and timings");
		test->add(inputOpts);
	}
};

#if 0
struct TagcollOptions : public MainParser<CommandParser>
{
	struct HelpGroup : public OptionGroup
	{
		BoolOption* help;
		BoolOption* version;

		HelpGroup()
		{
			add(help = new BoolOption("help", 'h', "help"));
			add(version = new BoolOption("version", 'V', "version"));
			help->shortNames.push_back('?');
			help->description = "print an help message and exit";
			version->description = "print the program version and exit";
			description = "Help options";
		}
		~HelpGroup()
		{
			delete help; delete version;
		}
	} helpGroup;


	struct Generic : public OptionParser
	{
		Generic(TagcollOptions* cp) : OptionParser("")
		{
			add(&cp->helpGroup);
		}
	} generic;
	struct Help : public OptionParser
	{
		Help(TagcollOptions* cp) : OptionParser("help")
		{
			usage = "[command]";
			description = "print help information";
		}
	} help;

#if 0
		//opts.add("verbose", 'v', "verbose", "enable verbose output");
		//opts.add("debug", 0, "debug", "enable debugging output (including verbose output)");
#endif
};
#endif

}
}

// vim:set ts=4 sw=4:
#endif