AnsibleGalaxy::noDeps()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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