compliance-trestle
compliance-trestle copied to clipboard
Ensure all trestle commands wrap a function / class that expects trestle root and 'effective cwd' to be passed, if required.
Issue description / feature objectives
The trestle command structure is built using the ilcli
classes which provides a need abstraction, however, the challenge is that functionality completed in the commands we may not want to expose to SDK users using the precise metholodolgy in the commands.
Put another way:
- Commands are making presumptions w.r.t. cwd and trestle root being inside of it.
The idea here would be that we shim all commands such that working directory and/or trestle root / other paths are normalized and passed into another interface.
This would simplify use for testing (e.g. most testing won't need to use argparse.Namespace
) and for higher level developer interfaces such as trestle.core.repository.
Completion Criteria
Interfaces completed across all commands.
The goal is to avoid contaminating command code with directory queries and manipulations. So the two main things needed are the root of the specific trestle project, referred to already as trestle_root, along with some indication of where in the project the operation is to be performed. The latter could be specified as 'effective_cwd', 'relative_path_to_trestle_root', or as an element path.
The problem with an element path is that it does not include the actual model name, and instead is just e.g. catalog.metadata.roles - and there is no 'mycatalog'. So I think specifying cwd as an absolute path is a reasonable approach. Some commands require loading a file directly from that directory - and that would be clean with cwd as an absolute path.
Ideally the cli methods would be structured as:
_run(args) -> do_command(trestle_root, [args is not passed in])
So the _run() command does simple parsing of the args and invokes a pure method that does not do any args parsing, and has an explicit trestle_root as the first parameter - if needed).
This way the underlying api method is pure and more declarative since it does minimal parsing of the arguments.
Most of the commands have trestle_root extracted, but a large number of commands do not have a pure invocation interface that does not receive args.