-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
219 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import sys | ||
|
||
from tackle.models import Context | ||
|
||
|
||
HELP_TEMPLATE = """ | ||
usage: tackle {{ input_string }} | ||
{% if positional_arguments is not None %}positional arguments: | ||
{% for i in positional_arguments %} | ||
{% endfor %}{% endif %} | ||
{% if positional_arguments is not None %}optional arguments: | ||
{% for i in optional_arguments %} | ||
{% endfor %}{% endif %} | ||
""" | ||
|
||
|
||
def find_help_functions(context: 'Context', args: list): | ||
|
||
# if len(args) == 0: | ||
# context.provider_hooks = | ||
|
||
for arg in args: | ||
if arg in context.context_functions: | ||
|
||
h = context.provider_hooks[arg] | ||
context.context_functions = "" | ||
print() | ||
|
||
|
||
def run_help(context: 'Context', args: list): | ||
""" | ||
Print the help screen then exit. Help can be displayed in three different scenarios. | ||
1. For the base (no args) -> this shows all the different function's help | ||
2. For a function (len(args) = 1) -> this shows function's help along with its | ||
associated methods. This is recursive so depends on depth of methods. | ||
3. For a function's methods (len(args) > 1) -> this drills into methods | ||
""" | ||
find_help_functions(context, args) | ||
help = [context.provider_hooks[i] for i in context.context_functions] | ||
for arg in args: | ||
if arg in context.context_functions: | ||
context.context_functions | ||
|
||
if len(args) >= 1: | ||
context.context_functions = [args.pop(0)] | ||
|
||
if len(args) != 0: | ||
# We need to drill down into methods | ||
raise NotImplementedError | ||
|
||
help_msg = [] | ||
for i in context.context_functions: | ||
hook_fields = context.provider_hooks[i].__fields__ | ||
|
||
if hook_fields['help'].default is None: | ||
continue | ||
|
||
help_msg.append(context.provider_hooks[i]) | ||
x = context.provider_hooks[i] | ||
z = context.provider_hooks[i].__fields__ | ||
print() | ||
|
||
print() | ||
sys.exit(0) | ||
|
||
# if len(args) == 0: | ||
# help_functions = context.context_functions | ||
# else: | ||
# for i, v in enumerate(args): | ||
# if i == 0: | ||
# if v not in context.context_functions: | ||
# print( | ||
# f"Help for {v} not available, declarative hook not in context.") | ||
# sys.exit(0) | ||
# help_functions = [args.pop(0)] | ||
# | ||
# # if len(args) >= 0: | ||
# for i, v in enumerate(args): | ||
# # Drill into functions | ||
|
||
# if len(args) >= 1: | ||
# # We have been asked for help on a function in the tackle file. Check if it | ||
# # exists and then drill into that func and then it's methods if len(args) > 1 | ||
# # if | ||
# | ||
# # for i in args: | ||
# # if i in | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
help: | ||
|
||
|
||
str: foo | ||
list: | ||
- stuff | ||
- things | ||
|
||
map: | ||
bar: baz | ||
ding: dong | ||
|
||
str_hook->: input | ||
list_hook->: | ||
- stuff | ||
- things | ||
|
||
map_hook->: | ||
bar: baz | ||
ding: dong | ||
|
||
|
||
with_help<-: | ||
help: Do stuff to things | ||
things: | ||
type: str | ||
description: The things | ||
render_by_default: true | ||
exec<-: | ||
p->: print {{things}} | ||
|
||
|
||
no_help<-: | ||
|
||
no_show_str: foo | ||
no_show_list: | ||
- foo | ||
- bar | ||
|
||
things: | ||
type: str | ||
description: The things | ||
render_by_default: true | ||
exec<-: | ||
p->: print {{things}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
with_help<-: | ||
help: Do stuff to things | ||
things: | ||
type: str | ||
description: The things | ||
render_by_default: true | ||
exec<-: | ||
p->: print {{things}} | ||
|
||
|
||
with_help_methods<-: | ||
help: Do stuff to things | ||
things: | ||
type: str | ||
description: The things | ||
render_by_default: true | ||
exec<-: | ||
p->: print {{things}} | ||
|
||
a_method_without_help<-: | ||
foo->: print bar | ||
|
||
a_method_with_help<-: | ||
help: Stuff n tings | ||
foo->: print bar | ||
|
||
no_help<-: | ||
no_show_str: foo | ||
no_show_list: | ||
- foo | ||
- bar | ||
|
||
things: | ||
type: str | ||
description: The things | ||
render_by_default: true | ||
exec<-: | ||
p->: print {{things}} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
|
||
from tackle.cli import main | ||
|
||
|
||
def test_cli_parse_args_help_arg_base(change_curdir_fixtures, capsys): | ||
with pytest.raises(SystemExit): | ||
main(["help.yaml", "help"]) | ||
out, err = capsys.readouterr() | ||
assert out == "Foo\n" | ||
print(out, err) | ||
|
||
|
||
def test_cli_parse_args_help_arg_for_func(change_curdir_fixtures, capsys): | ||
with pytest.raises(SystemExit): | ||
main(["help.yaml", "with_help", "help"]) | ||
out, err = capsys.readouterr() | ||
assert out == "Foo\n" | ||
print(out, err) | ||
|
||
|
||
def test_cli_parse_args_help_arg_for_func_with_method(change_curdir_fixtures, capsys): | ||
with pytest.raises(SystemExit): | ||
main(["help.yaml", "with_help_methods", "help"]) | ||
out, err = capsys.readouterr() | ||
assert out == "Foo\n" | ||
print(out, err) | ||
|
||
|
||
def test_cli_parse_args_help_arg_base_remote(change_curdir_fixtures, capsys): | ||
with pytest.raises(SystemExit): | ||
main(["robcxyz/tackle-hello-world", "help"]) | ||
out, err = capsys.readouterr() | ||
assert out == "Foo\n" | ||
print(out, err) | ||
|
||
|
||
def test_cli_parse_args_help_arg_for_func_remote(change_curdir_fixtures, capsys): | ||
with pytest.raises(SystemExit): | ||
main(["robcxyz/tackle-hello-world", "with_help", "help"]) | ||
out, err = capsys.readouterr() | ||
assert out == "Foo\n" | ||
print(out, err) |