E-MailRelay

gexecutablecommand.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gexecutablecommand.h
19///
20
21#ifndef G_EXECUTABLE_COMMAND_H
22#define G_EXECUTABLE_COMMAND_H
23
24#include "gdef.h"
25#include "gpath.h"
26#include "gstringarray.h"
27#include "gexception.h"
28#include <string>
29
30 namespace G
31{
32 class ExecutableCommand ;
33}
34
35//| \class G::ExecutableCommand
36/// A structure representing an external program, holding a path
37/// and a set of arguments. The constructor takes a complete command-line and splits it up
38/// into the executable part and a list of command-line parameters. If the
39/// command-line starts with a script then the contructed command-line may
40/// be for the appropriate interpreter (depending on the o/s).
41///
42/// \see G::Path, G::Args
43///
44 class G::ExecutableCommand
45{
46 public:
47 G_EXCEPTION( WindowsError , tx("cannot determine the windows directory") )
48
49 explicit ExecutableCommand( const std::string & command_line = {} ) ;
50 ///< Constructor taking a complete command-line. The
51 ///< command-line is split up on unescaped-and-unquoted
52 ///< space characters. Uses G::Arg::parse() in its
53 ///< implementation.
54
55 ExecutableCommand( const G::Path & exe , const StringArray & args ) ;
56 ///< Constructor taking the executable and arguments
57 ///< explicitly.
58
59 Path exe() const ;
60 ///< Returns the executable.
61
62 StringArray args() const ;
63 ///< Returns the command-line arguments.
64
65 void add( const std::string & arg ) ;
66 ///< Adds a command-line argument.
67
68 void insert( const G::StringArray & ) ;
69 ///< Inserts at the front of the command-line.
70 ///< The first element becomes the new executable.
71
72 std::string displayString() const ;
73 ///< Returns a printable representation for logging and diagnostics.
74
75 private:
76 G::Path m_exe ;
77 G::StringArray m_args ;
78} ;
79
80#endif
G::ExecutableCommand
A structure representing an external program, holding a path and a set of arguments.
Definition: gexecutablecommand.h:45
G::ExecutableCommand::ExecutableCommand
ExecutableCommand(const std::string &command_line={})
Constructor taking a complete command-line.
Definition: gexecutablecommand.cpp:29
G::ExecutableCommand::add
void add(const std::string &arg)
Adds a command-line argument.
Definition: gexecutablecommand.cpp:65
G::ExecutableCommand::args
StringArray args() const
Returns the command-line arguments.
Definition: gexecutablecommand.cpp:52
G::ExecutableCommand::displayString
std::string displayString() const
Returns a printable representation for logging and diagnostics.
Definition: gexecutablecommand.cpp:57
G::ExecutableCommand::insert
void insert(const G::StringArray &)
Inserts at the front of the command-line.
Definition: gexecutablecommand.cpp:71
G::ExecutableCommand::exe
Path exe() const
Returns the executable.
Definition: gexecutablecommand.cpp:47
G::Path
A Path object represents a file system path.
Definition: gpath.h:82
gexception.h
gpath.h
gstringarray.h
G
Low-level classes.
Definition: garg.h:36
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
G::tx
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84