CommandLine.h
Go to the documentation of this file.
1 /****
2  * CommandLine.h - Provides access to command-line parameters
3  *
4  * Copyright 2020 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming Framework Project
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with SHEM.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <WString.h>
23 #include <WVector.h>
24 
44 {
45 public:
49  struct Parameter {
53  const char* text{nullptr};
54 
55  operator bool() const
56  {
57  return text != nullptr;
58  }
59 
63  String getName() const;
64 
68  String getValue() const;
69  };
70 
74  class Parameters : public Vector<Parameter>
75  {
76  public:
81  Parameter find(const String& name) const;
82 
87  Parameter findIgnoreCase(const String& name) const;
88  };
89 
94  {
95  return parameters;
96  }
97 
98  /*
99  * Method called by startup code.
100  * All options have been processed so only parameters remain.
101  */
102  void parse(int paramCount, char* params[]);
103 
104 private:
105  Parameters parameters;
106 };
107 
108 extern CommandLine commandLine;
List of command-line parameters, in order.
Definition: CommandLine.h:74
String getName() const
Get parameter name, if there is one.
Parameter findIgnoreCase(const String &name) const
Fetch parameter by name.
The String class.
Definition: WString.h:136
const Parameters & getParameters()
Fetch a reference to the list of command-line parameters.
Definition: CommandLine.h:93
CommandLine commandLine
Provides access to the command line.
Definition: CommandLine.h:43
const char * text
The text exactly as presented on the command line.
Definition: CommandLine.h:53
Parameter find(const String &name) const
Fetch parameter by name.
Manages a single parameter, may be optionally separated into name=value.
Definition: CommandLine.h:49
void parse(int paramCount, char *params[])
Vector class template.
Definition: WVector.h:31
String getValue() const
Get parameter value.