1 | /* |
---|
2 | Copyright (C) 2007 by Robert Knight <robertknight@gmail.com> |
---|
3 | |
---|
4 | Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software |
---|
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
19 | 02110-1301 USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef SHELLCOMMAND_H |
---|
23 | #define SHELLCOMMAND_H |
---|
24 | |
---|
25 | // Qt |
---|
26 | #include <QStringList> |
---|
27 | |
---|
28 | namespace Konsole { |
---|
29 | |
---|
30 | /** |
---|
31 | * A class to parse and extract information about shell commands. |
---|
32 | * |
---|
33 | * ShellCommand can be used to: |
---|
34 | * |
---|
35 | * <ul> |
---|
36 | * <li>Take a command-line (eg "/bin/sh -c /path/to/my/script") and split it |
---|
37 | * into its component parts (eg. the command "/bin/sh" and the arguments |
---|
38 | * "-c","/path/to/my/script") |
---|
39 | * </li> |
---|
40 | * <li>Take a command and a list of arguments and combine them to |
---|
41 | * form a complete command line. |
---|
42 | * </li> |
---|
43 | * <li>Determine whether the binary specified by a command exists in the |
---|
44 | * user's PATH. |
---|
45 | * </li> |
---|
46 | * <li>Determine whether a command-line specifies the execution of |
---|
47 | * another command as the root user using su/sudo etc. |
---|
48 | * </li> |
---|
49 | * </ul> |
---|
50 | */ |
---|
51 | class ShellCommand { |
---|
52 | public: |
---|
53 | /** |
---|
54 | * Constructs a ShellCommand from a command line. |
---|
55 | * |
---|
56 | * @param fullCommand The command line to parse. |
---|
57 | */ |
---|
58 | ShellCommand(const QString & fullCommand); |
---|
59 | /** |
---|
60 | * Constructs a ShellCommand with the specified @p command and @p arguments. |
---|
61 | */ |
---|
62 | ShellCommand(const QString & command , const QStringList & arguments); |
---|
63 | |
---|
64 | /** Returns the command. */ |
---|
65 | QString command() const; |
---|
66 | /** Returns the arguments. */ |
---|
67 | QStringList arguments() const; |
---|
68 | |
---|
69 | /** |
---|
70 | * Returns the full command line. |
---|
71 | */ |
---|
72 | QString fullCommand() const; |
---|
73 | |
---|
74 | /** Returns true if this is a root command. */ |
---|
75 | bool isRootCommand() const; |
---|
76 | /** Returns true if the program specified by @p command() exists. */ |
---|
77 | bool isAvailable() const; |
---|
78 | |
---|
79 | /** Expands environment variables in @p text .*/ |
---|
80 | static QString expand(const QString & text); |
---|
81 | |
---|
82 | /** Expands environment variables in each string in @p list. */ |
---|
83 | static QStringList expand(const QStringList & items); |
---|
84 | |
---|
85 | private: |
---|
86 | QStringList _arguments; |
---|
87 | }; |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | #endif // SHELLCOMMAND_H |
---|
92 | |
---|