Skip to content

Add command

Christina-Kang edited this page Apr 5, 2018 · 2 revisions

Follow these instructions to add a new command to the CLI.

Determine command type

First, determine if the command needs to be a standard command, or a custom command. For information about these options, see the command mapping page.

Write custom command

If the command needs to be a new custom command, determine the command group it should fall under. The command group is usually something like node or cluster. The command group should correspond to the REST API target entity.

Write a new python function in the file that corresponds to the command group. The files with custom functions are in src/stctl/custom_<group>.py.

For more information, see the page on custom commands.

Find standard command

Look in the azure-servicefabric package for what standard commands exist. Every service fabric REST API will have a corresponding function of the same name.

For more information, see the page on standard commands.

Create a mapping

After finding or writing the python function, create a new command mapping. Determine the command name that you want to map the function to. For more information on picking a name, see the coding conventions.

Then, in the src/sfctl/commands.py file find the appropriate command group:

client_func_path = '<custom or standard>'
with CommandSuperGroup(__name__, self, client_func_path,
                       client_factory=client_create) as super_group:
    with super_group.group('<group>') as group:

Here client_func_path is azure.servicefabric#ServiceFabricClientAPIs.{} for standard commands and sfctl.custom_<group>#{} for custom commands.

Then, add an additional command by adding a line with your mapping:

group.command('<name>', '<function>')

Here <name> is the name of the command, and <function> is the python function name.

Write a test

For any custom commands, add unit tests to the appropriate command group file in src/sfctl/tests. Test the logic inside your custom python function that you previously wrote.

For all commands, add a paths generation test in paths_generation_test.py.

For all commands, add a help text verification test in help_text_test.py.

For custom commands, consider adding a scenario test in scenario_test.py that calls your command at least once.

For more information about testing, see testing.