Skip to content

Commit d1157f1

Browse files
committed
Adds DC/OS lib
Eliminates our dependency on the DC/OS lib until the day that dcos/dcos-cli#823 gets merged and we have a new lib.
1 parent 0d13b54 commit d1157f1

23 files changed

+5972
-6
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ For pointers on command usage run ``shazar -h``.
177177
Developers
178178
~~~~~~~~~~
179179

180+
> Note that we presently package the dcos library as source. When https://github.com/dcos/dcos-cli/pull/823 becomes available then
181+
we should remove this directory and depend on it directly.
182+
180183
For OS X, you should ensure firstly that you have the latest Xcode command line tools installed.
181184

182185
Now install the latest python3 version on your system, on OS X use:

conductr_cli/conduct_main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,20 @@ def build_parser(dcos_mode):
284284
def get_cli_parameters(args):
285285
parameters = ['']
286286
if not args.dcos_mode:
287-
if vars(args).get('scheme') != DEFAULT_SCHEME:
287+
arg = vars(args).get('scheme')
288+
if arg and arg != DEFAULT_SCHEME:
288289
parameters.append('--scheme {}'.format(args.scheme))
289-
if vars(args).get('ip') != host.resolve_default_ip():
290+
arg = vars(args).get('ip')
291+
if arg and arg != host.resolve_default_ip():
290292
parameters.append('--ip {}'.format(args.ip))
291-
if vars(args).get('port', int(DEFAULT_PORT)) != int(DEFAULT_PORT):
293+
arg = vars(args).get('port', int(DEFAULT_PORT))
294+
if arg and arg != int(DEFAULT_PORT):
292295
parameters.append('--port {}'.format(args.port))
293-
if vars(args).get('base_path', DEFAULT_BASE_PATH) != DEFAULT_BASE_PATH:
296+
arg = vars(args).get('base_path', DEFAULT_BASE_PATH)
297+
if arg and arg != DEFAULT_BASE_PATH:
294298
parameters.append('--base-path {}'.format(args.base_path))
295-
if vars(args).get('api_version', DEFAULT_API_VERSION) != DEFAULT_API_VERSION:
299+
arg = vars(args).get('api_version', DEFAULT_API_VERSION)
300+
if arg and arg != DEFAULT_API_VERSION:
296301
parameters.append('--api-version {}'.format(args.api_version))
297302
return ' '.join(parameters)
298303

dcos/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Version is set for releases by our build system.
2+
# Be extremely careful when modifying.
3+
version = 'SNAPSHOT'
4+
"""DC/OS version"""

dcos/cmds.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import collections
2+
3+
from dcos.errors import DCOSException
4+
5+
Command = collections.namedtuple(
6+
'Command',
7+
['hierarchy', 'arg_keys', 'function'])
8+
"""Describe a CLI command.
9+
10+
:param hierarchy: the noun and verbs that need to be set for the command to
11+
execute
12+
:type hierarchy: list of str
13+
:param arg_keys: the arguments that must get passed to the function; the order
14+
of the keys determines the order in which they get passed to
15+
the function
16+
:type arg_keys: list of str
17+
:param function: the function to execute
18+
:type function: func(args) -> int
19+
"""
20+
21+
22+
def execute(cmds, args):
23+
"""Executes one of the commands based on the arguments passed.
24+
25+
:param cmds: commands to try to execute; the order determines the order of
26+
evaluation
27+
:type cmds: list of Command
28+
:param args: command line arguments
29+
:type args: dict
30+
:returns: the process status
31+
:rtype: int
32+
"""
33+
34+
for hierarchy, arg_keys, function in cmds:
35+
# Let's find if the function matches the command
36+
match = True
37+
for positional in hierarchy:
38+
if not args[positional]:
39+
match = False
40+
41+
if match:
42+
params = [args[name] for name in arg_keys]
43+
return function(*params)
44+
45+
raise DCOSException('Could not find a command with the passed arguments')

0 commit comments

Comments
 (0)