Skip to content

Commit 2a87131

Browse files
committed
-
1 parent 5539b90 commit 2a87131

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

src/mash/shell/ast/set_definition.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ def __init__(self, items, condition=None):
2727

2828
def run(self, prev_result='', shell: BaseShell = None, lazy=False):
2929
items = []
30-
with shell.use_mode(Mode.COMPILE):
31-
for item in self.items.values:
32-
results = shell.run_commands(item)
30+
for item in self.items.values:
31+
with shell.use_mode(Mode.COMPILE):
32+
results = shell.run_commands(item, '', not lazy)
33+
34+
if results is None:
35+
return
36+
37+
if isinstance(results, dict):
38+
for k, v in results.items():
39+
# TODO use values
40+
items.append((str(k),))
41+
else:
3342
for row in results:
3443
items.append(row.splitlines())
3544

@@ -46,6 +55,10 @@ def apply(self, items, shell: BaseShell = None):
4655
yield from product(*items)
4756
return
4857

58+
if 1:
59+
# TODO remove
60+
yield from product(*items)
61+
return
4962
for element in product(*items):
5063
result = shell.run_commands(self.condition, element)
5164
if result:

src/mash/shell/with_filesystem.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ def init_shell(self, *build_args, **build_kwds):
4848

4949
def _set_shell_functions(self, cls):
5050
# convert methods to functions
51-
cd = partial_simple(self.repository.cd)
5251
ll = partial_simple(self.repository.ll)
5352

54-
set_functions({'cd': cd,
55-
'use': cd,
53+
set_functions({'cd': partial_simple(self.repository.cd),
54+
'use': partial_simple(self.use),
5655
'l': ll,
5756
'list': ll,
5857
'foreach': partial_simple(self.foreach),
@@ -84,6 +83,16 @@ def pwd(self):
8483
"""
8584
return ' '.join(self.repository.full_path)
8685

86+
def use(self, *path: str):
87+
"""Access a directory.
88+
Change directory in REPL mode, otherwise return the directory.
89+
"""
90+
if self.shell.mode == Mode.REPL:
91+
return self.repository.cd(*path)
92+
elif self.shell.mode == Mode.COMPILE:
93+
return self.get(*path)
94+
raise NotImplementedError(self.shell.mode)
95+
8796
def get(self, *path: str):
8897
"""Return the value of the file associated with `path`.
8998
"""
@@ -164,7 +173,7 @@ def add_cd_alias(self, dirname: str):
164173
# create alias
165174
func = partial(self.repository.cd, dirname)
166175
name = f'{self.repository.cd.__name__}({dirname})'
167-
cd_dirname = Function(func, name, f'cd {dirname}')
176+
cd_dirname = Function(func, name, f'use {dirname}')
168177

169178
self.shell.add_functions({dirname: cd_dirname},
170179
group_key=cd_aliasses)
@@ -209,19 +218,10 @@ def default_method(self, dirname: str):
209218
if candidates:
210219
error = hamming(dirname, str(candidates[0]))
211220
if error < 0.8:
212-
if self.shell.mode == Mode.REPL:
213-
self.repository.cd(candidates[0])
214-
return
215-
elif self.shell.mode == Mode.COMPILE:
216-
return self.get(candidates[0])
221+
return self.use(candidates[0])
217222

218223
if is_digit(dirname):
219-
if self.shell.mode == Mode.REPL:
220-
self.repository.cd(dirname)
221-
return
222-
elif self.shell.mode == Mode.COMPILE:
223-
return self.get(dirname)
224-
224+
return self.use(dirname)
225225

226226
debug('No matching directory found')
227227
return dirname

test/shell/test_shell_rest_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def test_rest_client_standard_set():
121121
shell, _ = init()
122122
shell = shell.shell
123123

124-
result = catch_output(r'{users}', shell=shell)
124+
result = catch_output(r'{user}', shell=shell)
125+
assert '1000' in result
126+
assert '1002' in result
125127
result = catch_output(r'{users} >>= show $.id', shell=shell)
126128
# TODO add assertions
127129
# assert '1001' in result

0 commit comments

Comments
 (0)