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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
#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 <tagcoll/Commandline.h>
namespace Tagcoll {
namespace commandline {
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 InputGroup : public OptionGroup
{
ExistingFileOption* derived;
ExistingFileOption* extimpl;
ExistingFileOption* rename;
ExistingFileOption* patch;
BoolOption* rmunfaceted;
StringOption* rmtags;
InputGroup()
{
add(derived = new ExistingFileOption("derived-tags-from", 0, "derived"));
add(extimpl = new ExistingFileOption("extimpl", 0, "implications-from"));
add(rename = new ExistingFileOption("rename", 0, "rename-from"));
add(patch = new ExistingFileOption("patch", 'p', "patch-with"));
add(rmunfaceted = new BoolOption("rmunfaceted", 0, "remove-unfaceted"));
add(rmtags = new StringOption("rmtags", 0, "remove-tags"));
derived->description = "expand derived tags using the given list";
extimpl->description = "use an external list of implications";
rename->description = "rename tags using the given mapping list";
patch->description = "apply patches from the given tag patch file";
patch->longNames.push_back("patch");
rmunfaceted->description = "while parsing, remove all tags with no facet part";
rmtags->usage = "<expression>";
rmtags->description = "while parsing, remove all tags matching the given tag expression";
description = "Options controlling transformations of input data";
}
~InputGroup()
{
delete derived; delete extimpl; delete rename; delete patch;
delete rmunfaceted; delete rmtags;
}
} inputGroup;
struct OutputGroup : public OptionGroup
{
BoolOption* group;
BoolOption* redundant;
BoolOption* itemsOnly;
OutputGroup()
{
add(group = new BoolOption("group", 'g', "group"));
add(redundant = new BoolOption("redundant", 0, "redundant"));
add(itemsOnly = new BoolOption("items", 'i', "items"));
group->description = "group items with the same tagset in the output collection";
group->longNames.push_back("group-items");
redundant->description = "when implications are provided, expand them explicitly in the output";
itemsOnly->description = "output only the names of the items, without the tags";
description = "Options controlling transformations of output data";
}
~OutputGroup()
{
delete group;
delete redundant;
}
} outputGroup;
struct HierarchyGroup : public OptionGroup
{
IntOption* flatten;
IntOption* filter;
HierarchyGroup()
{
add(flatten = new IntOption("flatten", 0, "flatten-threshold"));
add(filter = new IntOption("filter", 'f', "filter"));
flatten->description = "set the number of total items below which a branch is flattened when using the \"hierarchy\" command (defaults to 0, meaning \"don't flatten\")";
filter->description = "filter out the tags with cardinality less than the given value (defaults to not filter; currently only works when building hierarchies)";
description = "Options controlling generation of tag hierarchies";
}
~HierarchyGroup()
{
delete flatten;
delete filter;
}
} hierarchyGroup;
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 informations";
}
} help;
struct Copy : public OptionParser
{
Copy(TagcollOptions* cp) : OptionParser("copy")
{
usage = "[files...]";
description = "output the collection";
longDescription =
"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.";
add(&cp->inputGroup);
add(&cp->outputGroup);
add(&cp->helpGroup);
aliases.push_back("cat");
}
} copy;
struct Reverse : public OptionParser
{
StringOption* untaggedTag;
Reverse(TagcollOptions* cp) : OptionParser("reverse")
{
add(untaggedTag = new StringOption("untagged-tag", 0, "untagged-tag"));
untaggedTag->usage = "<tag>";
untaggedTag->description = "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";
usage = "[files...]";
description = "\"reverse\" the collection, outputting one with items associated to tags";
longDescription =
"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.";
add(&cp->inputGroup);
add(&cp->outputGroup);
add(&cp->helpGroup);
}
~Reverse()
{
delete untaggedTag;
}
} reverse;
struct Diff : public OptionParser
{
Diff(TagcollOptions* cp) : OptionParser("diff")
{
usage = "<file1> <file2>";
description = "output a tag patch file with the differences between two files";
longDescription =
"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.";
add(&cp->helpGroup);
}
} diff;
struct Related : public OptionParser
{
IntOption* distance;
Related(TagcollOptions* cp) : OptionParser("related")
{
add(distance = new IntOption("distance", 'd', "distance"));
distance->description = "set the maximum distance to use for the \"related\" command (defaults to 0)";
usage = "<item> [files...]";
description = "print a list of items related to the given one";
longDescription =
"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.";
examples = "tagcoll related mutt,mozilla-browser -";
add(&cp->inputGroup);
add(&cp->helpGroup);
}
~Related()
{
delete distance;
}
} related;
struct Implications : public OptionParser
{
Implications(TagcollOptions* cp) : OptionParser("implications")
{
usage = "[files...]";
description = "compute a list of tag implications";
longDescription =
"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.";
examples =
"C:devel,languages\n"
"ada:devel,languages\n"
"apachemodules:net,servers,web\n"
"browsers:net,web\n";
add(&cp->inputGroup);
add(&cp->helpGroup);
}
} implications;
struct Hierarchy : public OptionParser
{
Hierarchy(TagcollOptions* cp) : OptionParser("hierarchy")
{
usage = "[files...]";
description = "build a smart hierarchy with the collection data";
longDescription =
"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.";
examples =
"/net/clients/mail: mutt\n"
"/net/filters/mail: procmail\n";
add(&cp->inputGroup);
add(&cp->hierarchyGroup);
add(&cp->helpGroup);
}
} hierarchy;
struct CleanHierarchy : public OptionParser
{
CleanHierarchy(TagcollOptions* cp) : OptionParser("cleanhierarchy")
{
usage = "[files...]";
description = "build a cleaned smart hierarchy with the collection data";
longDescription =
"Like hiearchy, but in every node it merges tags which are attached to the "
"same set of items.";
add(&cp->inputGroup);
add(&cp->hierarchyGroup);
add(&cp->helpGroup);
}
} cleanhierarchy;
struct FindSpecials : public OptionParser
{
FindSpecials(TagcollOptions* cp) : OptionParser("findspecials")
{
usage = "[files...]";
description =
"generate a smart hierarchy and print, for each toplevel tag, "
"what are the items that make it toplevel instead of going below "
"another tag";
add(&cp->inputGroup);
add(&cp->hierarchyGroup);
add(&cp->helpGroup);
}
} findspecials;
struct Grep : public OptionParser
{
Grep(TagcollOptions* cp) : OptionParser("grep")
{
usage = "<expression> [files...]";
description = "output the collection of tags that match the given tag expression";
add(&cp->inputGroup);
add(&cp->outputGroup);
add(&cp->helpGroup);
}
} grep;
TagcollOptions() : MainParser<CommandParser>("tagcoll"),
generic(this),
help(this), copy(this), reverse(this), diff(this), related(this), implications(this),
hierarchy(this), cleanhierarchy(this), findspecials(this), grep(this)
{
add(generic);
add(help);
add(copy);
add(reverse);
add(diff);
add(related);
add(implications);
add(hierarchy);
add(cleanhierarchy);
add(findspecials);
add(grep);
usage = "<command> [options and arguments]";
description = "Perform various operations on a tagged collection";
}
#if 0
//opts.add("verbose", 'v', "verbose", "enable verbose output");
//opts.add("debug", 0, "debug", "enable debugging output (including verbose output)");
#endif
};
}
}
// vim:set ts=4 sw=4:
#endif
|