E-MailRelay
gexecutablecommand.cpp
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.cpp
19///
20
21#include "gdef.h"
22#include "gexecutablecommand.h"
23#include "garg.h"
24#include "gstr.h"
25#include <algorithm>
26#include <iterator>
27
28#ifndef G_LIB_SMALL
30{
31 if( !s.empty() )
32 {
33 m_args = Arg(s).array() ;
34 m_exe = m_args.at(0U) ;
35 std::rotate( m_args.begin() , m_args.begin()+1U , m_args.end() ) ;
36 m_args.pop_back() ; // remove exe
37 }
38}
39#endif
40
42 m_exe(exe_) ,
43 m_args(args_)
44{
45}
46
48{
49 return m_exe ;
50}
51
53{
54 return m_args ;
55}
56
58{
59 return
60 m_args.empty() ?
61 std::string("[") + m_exe.str() + "]" :
62 std::string("[") + m_exe.str() + "] [" + Str::join("] [",m_args) + "]" ;
63}
64
65void G::ExecutableCommand::add( const std::string & arg )
66{
67 m_args.push_back( arg ) ;
68}
69
70#ifndef G_LIB_SMALL
72{
73 if( !array.empty() )
74 {
75 m_args.insert( m_args.begin() , m_exe.str() ) ;
76 m_args.insert( m_args.begin() , std::next(array.begin()) , array.end() ) ;
77 m_exe = m_args.at( 0U ) ;
78 }
79}
80#endif
81
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
Definition: garg.h:50
StringArray array(unsigned int shift=0U) const
Returns the arguments as a string array, with an optional shift.
Definition: garg.cpp:88
ExecutableCommand(const std::string &command_line={})
Constructor taking a complete command-line.
void add(const std::string &arg)
Adds a command-line argument.
StringArray args() const
Returns the command-line arguments.
std::string displayString() const
Returns a printable representation for logging and diagnostics.
void insert(const G::StringArray &)
Inserts at the front of the command-line.
Path exe() const
Returns the executable.
A Path object represents a file system path.
Definition: gpath.h:82
static std::string join(std::string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
Definition: gstr.cpp:1221
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30