comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/mash/Command.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
comparison
equal deleted inserted replaced
67:0e9998148a16 69:33d812a61356
1 // Copyright © 2015, Battelle National Biodefense Institute (BNBI);
2 // all rights reserved. Authored by: Brian Ondov, Todd Treangen,
3 // Sergey Koren, and Adam Phillippy
4 //
5 // See the LICENSE.txt file included with this software for license information.
6
7 #ifndef INCLUDED_Command
8 #define INCLUDED_Command
9
10 #include <map>
11 #include <string>
12 #include <vector>
13 #include <set>
14
15 namespace mash {
16
17 class Command
18 {
19
20 // A base class for handling command line parsing and usage messages. Specific
21 // commands can be implemented by subclassing and overriding the run() method.
22 // The run() method will be called by this base class from run(argc, argv) once
23 // it has parsed options, which can be accessed from the 'options' map using the
24 // name strings given when adding them (not 'identifier', which is its parsing
25 // name to appear after the '-'). Arguments (i.e. operands given after the
26 // options on the command line) will be available in the 'arguments' vector.
27
28 public:
29
30 class Option
31 {
32 public:
33
34 enum Type
35 {
36 Boolean,
37 Number,
38 Integer,
39 Size,
40 File,
41 String
42 }
43 type;
44
45 std::string category;
46 std::string identifier;
47 std::string description;
48 std::string argument;
49 std::string argumentDefault;
50
51 float argumentAsNumber;
52 float argumentMin;
53 float argumentMax;
54
55 bool active;
56 bool changed;
57
58 Option() {}
59 Option(Type typeNew, std::string identifierNew, std::string categoryNew, std::string descriptionNew, std::string argumentDefaultNew = "", float argumentMinNew = 0, float argumentMaxNew = 0);
60
61 float getArgumentAsNumber() const {return argumentAsNumber;}
62 void setArgument(std::string argumentNew);
63 };
64
65 Command();
66 virtual ~Command() {};
67
68 void addOption(std::string name, Option option);
69 const Option & getOption(std::string name) const;
70 inline bool hasOption(std::string name) const {return options.count(name);}
71 void print() const;
72 virtual int run() const = 0;
73 int run(int argc, const char ** argv);
74
75 std::string name;
76 std::string summary;
77 std::string description;
78 std::string argumentString;
79
80 protected:
81
82 void useOption(std::string name);
83 void useSketchOptions();
84
85 std::map<std::string, Option> options;
86 std::map<std::string, Option> optionsAvailable;
87 std::vector<std::string> arguments;
88
89 private:
90
91 void addAvailableOption(std::string name, Option option);
92 void addCategory(std::string name, std::string displayName);
93
94 std::map<std::string, std::string> optionNamesByIdentifier;
95 std::map<std::string, std::vector<std::string> > optionNamesByCategory;
96 std::vector<std::string> categories;
97 std::map<std::string, std::string> categoryDisplayNames;
98 };
99
100 inline const Command::Option & Command::getOption(std::string name) const {return options.at(name);}
101 void splitFile(const std::string & file, std::vector<std::string> & lines);
102 void printColumns(const std::vector<std::vector<std::string>> & columns, int indent = 2, int spacing = 2, const char * missing = "-", int max = 80);
103 void printColumns(const std::vector<std::vector<std::string>> & columns, const std::vector<std::pair<int, std::string>> & dividers, int indent = 2, int spacing = 2, const char * missing = "-", int max = 80);
104
105 } // namespace mash
106
107 #endif