Completed
Pull Request — master (#27)
by
unknown
03:26
created

AnsibleGalaxy::server()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of the php-ansible package.
4
 *
5
 * (c) Marc Aschmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Asm\Ansible\Command;
12
13
/**
14
 * Class AnsibleGalaxy
15
 *
16
 * @package Asm\Ansible\Command
17
 * @author Marc Aschmann <[email protected]>
18
 */
19
final class AnsibleGalaxy extends AbstractAnsibleCommand implements AnsibleGalaxyInterface
20
{
21
22
    /**
23
     * Executes a command process.
24
     * Returns either exitcode or string output if no callback is given.
25
     *
26
     * @param null $callback
27
     * @return integer|string
28
     */
29 1
    public function execute($callback = null)
30
    {
31 1
        return $this->runProcess($callback);
32
    }
33
34
    /**
35
     * Initialize a new role with base structure.
36
     *
37
     * @param string $roleName
38
     * @return $this
39
     */
40 1
    public function init($roleName)
41
    {
42 1
        $this
43 1
            ->addBaseoption('init')
44 1
            ->addBaseoption($roleName);
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * @param string $role
51
     * @param string $version
52
     * @return $this
53
     */
54 2
    public function info($role, $version = '')
55
    {
56 2
        if ('' !== $version) {
57 1
            $role = $role . ',' . $version;
58 1
        }
59
60 2
        $this
61 2
            ->addBaseoption('info')
62 2
            ->addBaseoption($role);
63
64 2
        return $this;
65
    }
66
67
    /**
68
     * Install packages.
69
     *
70
     * If you are unsure whether the role(s) is already installed,
71
     * either check first or use the "force" option.
72
     *
73
     * @param string|array $roles role_name(s)[,version] | scm+role_repo_url[,version]
74
     * @return $this
75
     */
76 3
    public function install($roles = '')
77
    {
78 3
        $roles = $this->checkParam($roles, ' ');
79
80 3
        $this->addBaseoption('install');
81
82 3
        if ('' !== $roles) {
83 2
            $this->addBaseoption($roles);
84 2
        }
85
86 3
        return $this;
87
    }
88
89
    /**
90
     * Get a list of installed modules.
91
     *
92
     * @param string $roleName
93
     * @return string list of installed modules
94
     */
95 3
    public function modulelist($roleName = '')
96
    {
97 3
        $this->addBaseoption('list');
98
99 3
        if ('' !== $roleName) {
100 1
            $this->addBaseoption($roleName);
101 1
        }
102
103 3
        return $this;
104
    }
105
106
    /**
107
     * Add package(s)
108
     *
109
     * @param string|array $roles
110
     * @return $this
111
     */
112 2
    public function remove($roles = '')
113
    {
114 2
        $roles = $this->checkParam($roles, ' ');
115
116 2
        $this
117 2
            ->addBaseoption('remove')
118 2
            ->addBaseoption($roles);
119
120 2
        return $this;
121
    }
122
123
    /**
124
     * Show general or specific help.
125
     *
126
     * @return $this
127
     */
128 1
    public function help()
129
    {
130 1
        $this->addParameter('--help');
131
132 1
        return $this;
133
    }
134
135
    /**
136
     * The path in which the skeleton role will be created.
137
     * The default is the current working directory.
138
     *
139
     * @param string $path
140
     * @return $this
141
     */
142 1
    public function initPath($path = '')
143
    {
144 1
        $this->addOption('--init-path', $path);
145
146 1
        return $this;
147
    }
148
149
    /**
150
     * Don't query the galaxy API when creating roles.
151
     *
152
     * @return $this
153
     */
154 1
    public function offline()
155
    {
156 1
        $this->addParameter('--offline');
157
158 1
        return $this;
159
    }
160
161
    /**
162
     * The API server destination.
163
     *
164
     * @param string $apiServer
165
     * @return $this
166
     */
167 2
    public function server($apiServer)
168
    {
169 2
        $this->addOption('--server', $apiServer);
170
171 2
        return $this;
172
    }
173
174
    /**
175
     * Force overwriting an existing role.
176
     *
177
     * @return $this
178
     */
179 2
    public function force()
180
    {
181 2
        $this->addParameter('--force');
182
183 2
        return $this;
184
    }
185
186
    /**
187
     * A file containing a list of roles to be imported.
188
     *
189
     * @param string $roleFile FILE
190
     * @return $this
191
     */
192 1
    public function roleFile($roleFile)
193
    {
194 1
        $this->addOption('--role-file', $roleFile);
195
196 1
        return $this;
197
    }
198
199
    /**
200
     * The path to the directory containing your roles.
201
     *
202
     * The default is the roles_path configured in your
203
     * ansible.cfg file (/etc/ansible/roles if not configured).
204
     *
205
     * @param string $rolesPath
206
     * @return $this
207
     */
208 1
    public function rolesPath($rolesPath)
209
    {
210 1
        $this->addOption('--roles-path', $rolesPath);
211
212 1
        return $this;
213
    }
214
215
    /**
216
     * Ignore errors and continue with the next specified role.
217
     *
218
     * @return $this
219
     */
220 1
    public function ignoreErrors()
221
    {
222 1
        $this->addParameter('--ignore-errors');
223
224 1
        return $this;
225
    }
226
227
    /**
228
     * Don't download roles listed as dependencies.
229
     *
230
     * @return $this
231
     */
232 1
    public function noDeps()
233
    {
234 1
        $this->addParameter('--no-deps');
235
236 1
        return $this;
237
    }
238
239
    /**
240
     * Get parameter string which will be used to call ansible.
241
     *
242
     * @param bool $asArray
243
     * @return string|array
244
     */
245 11
    public function getCommandlineArguments($asArray = true)
246
    {
247 11
        return $this->prepareArguments($asArray);
248
    }
249
}
250