-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proposal for cli-commands api (#15630)
* proposal for cli-commands api * subcommand * Add test for custom command that calls the create command * fixes * new test to reuse other custom --------- Co-authored-by: Luis Caro Campos <3535649+jcar87@users.noreply.github.com>
- Loading branch information
1 parent
fc85491
commit e2a6d96
Showing
5 changed files
with
160 additions
and
0 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
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,24 @@ | ||
from conans.errors import ConanException | ||
|
||
|
||
class CommandAPI: | ||
|
||
def __init__(self, conan_api): | ||
self.conan_api = conan_api | ||
self.cli = None | ||
|
||
def run(self, cmd): | ||
if isinstance(cmd, str): | ||
cmd = cmd.split() | ||
if isinstance(cmd, list): | ||
current_cmd = cmd[0] | ||
args = cmd[1:] | ||
else: | ||
raise ConanException("Input of conan_api.command.run() should be a list or a string") | ||
commands = getattr(self.cli, "_commands") # to no make it public to users of Cli class | ||
try: | ||
command = commands[current_cmd] | ||
except KeyError: | ||
raise ConanException(f"Command {current_cmd} does not exist") | ||
|
||
return command.run_cli(self.conan_api, args) |
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
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