0.9.0 feature: "Appendable snippets"
by Bohuslav Kabrda
Hi all,
there's a new feature that I've discussed few weeks back with Miro Hroncok and now I finally came to standardizing it. I call it "Appendable snippets".
Current problem:
- There is certain functionality that we store in snippets, for example --github or --eclipse.
- There are pieces of code that we need to put in every assistant in order to use these - in args, dependencies, and run section. This leads to annoying code duplication and fixing at more places when needed.
I think we can do better - we can produce snippets, whose args/dependencies/run sections will (semi)automatically be appended to certain assistants. An example:
Appendable snippet:
---foo.yaml
args:
with_foo:
flags: [--with-foo, -f]
extends: crt/*
foo:
flags: [--foo, -f]
extends: mod/bar*;mod/spam
dependencies:
- rpm: ['foo']
dependencies_python:
- rpm: ['python-foo']
run:
- log_i: running generic foo ...
run_python:
- log_i: running python-specific foo ...
---foo.yaml
Explanation:
- Every snippet becomes appendable when any of its args has "extends" attribute.
- This appendable snippet will add a --with-foo option to all "crt" assistants and --foo option to all assistants whose path matches any of the two regexps specified (maybe something simpler like glob.glob would be better for this).
- If the given option is used on an assistant invocation, few things will happen:
-- 'dependencies' will always get installed; moreover, if 'creator used to create this project (some background magic will happen to find this out)' was under crt/python, 'dependencies_python' will get used (similar to modifier assistants).
-- If 'creator used to create this project (some background magic will happen to find this out)' was under crt/python, run_python will be used, otherwise just 'run' (similar to modifier assistants). 'run' sections of all snippets will execute on a specially marked place in assistant. If no such place is marked, they will execute between 'run' and 'post_run' of the assistant.
-- Appendables will run in the order specified on command line.
- This snippet still remains usable as any other snippet.
Usage in assistants:
Since number of appendable snippets can get extremely high, I'd suggest to _not_ show them in CLI help/GUI:
- GUI will provide sth. like dropdown "show more options", that will display appendables.
- CLI will provide an action, e.g. "da appendables", that will list these.
- That also probably means that CLI should require appendables to go after a '--' delimiter to clearly separate them:
da crt python django -n foo -- --appendables --go --here
- Appendables will probably greatly reduce current modifiers because they'll substitute most of their functionality.
Now, we'll probably want to advise using certain types of functionality, therefore we'll want to make certain appendables show up for certain projects in help/default arguments. Therefore I'd suggest using "use: [foo:with_foo]" in assistants to say that "argument with_foo from foo snippet should show up in help by default".
Comments/suggestions/ideas?
Thanks,
Slavek.
10 years, 2 months