commandline¶
The osc.commandline module provides functionality for creating osc command-line plugins.
-
class
osc.commandline.OscCommand(full_name, parent=None)¶ Inherit from this class to create new commands.
The first line of the docstring becomes the help text, the remaining lines become the command description.
-
add_argument(*args, **kwargs)¶ Add a new argument to the command’s argument parser. See argparse documentation for allowed parameters.
-
get_description()¶ Return the description of the command. The docstring without the first line is returned by default.
-
get_help()¶ Return the help text of the command. The first line of the docstring is returned by default.
-
init_arguments()¶ Override to add arguments to the argument parser.
Note
Make sure you’re adding arguments only by calling
self.add_argument(). Usingself.parser.add_argument()directly is not recommended because it disables argument intermixing.
-
main_command¶ Return reference to the main command that represents the executable and contains the main instance of ArgumentParser.
-
run(args)¶ Override to implement the command functionality.
Note
args.positional_argsis a list containing any unknown (unparsed) positional arguments.Note
Consider moving any reusable code into a library, leaving the command-line code only a thin wrapper on top of it.
If the code is generic enough, it should be added to osc directly. In such case don’t hesitate to open an issue.
-
-
class
osc.commandline.OscMainCommand¶ -
classmethod
main(argv=None, run=True)¶ Initialize OscMainCommand, load all commands and run the selected command.
-
classmethod
-
osc.commandline.ensure_no_remaining_args(args)¶ Error out when args still contains arguments.
Raises: oscerr.WrongArgs – The args list still contains arguments.
-
osc.commandline.pop_project_package_from_args(args: List[str], project_is_optional: bool = False, default_project: str = None, package_is_optional: bool = False, default_package: str = None)¶ Pop project and package from given args. They may be either 2 individual entries or a single entry with values separated with “/”.
Warning
The args list gets modified in this function call!
Parameters: - args (list(str)) – List of command-line arguments.
- project_is_optional (bool) – Whether to error out when project cannot be retrieved. Implies package_is_optional=False.
- default_project (str) – Used if project is not specified in args. Resolved from the current working copy if set to ‘.’.
- package_is_optional (bool) – Whether to error out when package cannot be retrieved.
- default_package (str) – Used if package is not specified in args. Resolved from the current working copy if set to ‘.’.
Returns: Project and package.
Return type: tuple(str)
-
osc.commandline.pop_project_package_targetproject_targetpackage_from_args(args: List[str], project_is_optional: bool = False, default_project: str = None, package_is_optional: bool = False, default_package: str = None, target_project_is_optional: bool = False, default_target_project: str = None, target_package_is_optional: bool = False, default_target_package: str = None)¶ Pop project, package, target project and target package from given args.
Warning
The args list gets modified in this function call!
Parameters: - args (list(str)) – List of command-line arguments.
- project_is_optional (bool) – Whether to error out when project cannot be retrieved. Implies package_is_optional=False.
- default_project (str) – Used if project is not specified in args. Resolved from the current working copy if set to ‘.’.
- package_is_optional (bool) – Whether to error out when package cannot be retrieved.
- default_package (str) – Used if package is not specified in args. Resolved from the current working copy if set to ‘.’.
- target_project_is_optional (bool) – Whether to error out when target project cannot be retrieved. Implies target_package_is_optional=False.
- default_target_project (str) – Used if target project is not specified in args. Resolved from the current working copy if set to ‘.’.
- target_package_is_optional (bool) – Whether to error out when target package cannot be retrieved.
- default_target_package (str) – Used if target package is not specified in args. Resolved from the current working copy if set to ‘.’.
Returns: Project, package, target project and target package.
Return type: tuple(str)
-
osc.commandline.pop_project_package_repository_arch_from_args(args: List[str], project_is_optional: bool = False, default_project: str = None, package_is_optional: bool = False, default_package: str = None, repository_is_optional: bool = False, default_repository: str = None, arch_is_optional: bool = False, default_arch: str = None)¶ Pop project, package, repository and arch from given args.
Warning
The args list gets modified in this function call!
Parameters: - args (list(str)) – List of command-line arguments.
- project_is_optional (bool) – Whether to error out when project cannot be retrieved. Implies package_is_optional=False.
- default_project (str) – Used if project is not specified in args. Resolved from the current working copy if set to ‘.’.
- package_is_optional (bool) – Whether to error out when package cannot be retrieved.
- default_package (str) – Used if package is not specified in args. Resolved from the current working copy if set to ‘.’.
- repository_is_optional (bool) – Whether to error out when project cannot be retrieved. Implies arch_is_optional=False.
- default_repository (str) – Used if repository is not specified in args.
- arch_is_optional (bool) – Whether to error out when arch cannot be retrieved.
- default_arch (str) – Used if arch is not specified in args.
Returns: Project, package, repository and arch.
Return type: tuple(str)
-
osc.commandline.pop_repository_arch_from_args(args: List[str], repository_is_optional: bool = False, default_repository: str = None, arch_is_optional: bool = False, default_arch: str = None)¶ Pop repository and arch from given args. They may be either 2 individual entries or a single entry with values separated with “/”.
Warning
The args list gets modified in this function call!
Parameters: - args (list(str)) – List of command-line arguments.
- repository_is_optional (bool) – Whether to error out when project cannot be retrieved. Implies arch_is_optional=False.
- default_repository (str) – Used if repository is not specified in args.
- arch_is_optional (bool) – Whether to error out when arch cannot be retrieved.
- default_arch (str) – Used if arch is not specified in args.
Returns: Repository and arch.
Return type: tuple(str)