File: ShellCommand.h

package info (click to toggle)
qmlkonsole 25.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,680 kB
  • sloc: cpp: 12,794; xml: 345; makefile: 3; sh: 1
file content (77 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download | duplicates (4)
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
/*
    SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef SHELLCOMMAND_H
#define SHELLCOMMAND_H

// Qt
#include <QStringList>

namespace Konsole
{
/**
 * A class to parse and extract information about shell commands.
 *
 * ShellCommand can be used to:
 *
 * <ul>
 *      <li>Take a command-line (eg "/bin/sh -c /path/to/my/script") and split it
 *          into its component parts (eg. the command "/bin/sh" and the arguments
 *          "-c","/path/to/my/script")
 *      </li>
 *      <li>Take a command and a list of arguments and combine them to
 *          form a complete command line.
 *      </li>
 *      <li>Determine whether the binary specified by a command exists in the
 *          user's PATH.
 *      </li>
 *      <li>Determine whether a command-line specifies the execution of
 *          another command as the root user using su/sudo etc.
 *      </li>
 * </ul>
 */
class ShellCommand
{
public:
    /**
     * Constructs a ShellCommand from a command line.
     *
     * @param aCommand The command line to parse.
     */
    explicit ShellCommand(const QString &aCommand);
    /**
     * Constructs a ShellCommand with the specified @p aCommand and @p aArguments.
     */
    ShellCommand(const QString &aCommand, const QStringList &aArguments);

    /** Returns the command. */
    QString command() const;
    /** Returns the arguments. */
    QStringList arguments() const;

    /**
     * Returns the full command line.
     */
    QString fullCommand() const;

    /** Expands environment variables in @p text .*/
    static QString expand(const QString &text);

    /** Expands environment variables in each string in @p list. */
    static QStringList expand(const QStringList &items);

    static bool isValidEnvCharacter(const QChar &ch);

    static bool isValidLeadingEnvCharacter(const QChar &ch);

private:
    static bool expandEnv(QString &text);

    QStringList _arguments;
};
}

#endif // SHELLCOMMAND_H