Skip to content
This repository was archived by the owner on Sep 15, 2020. It is now read-only.

consolidate options to global options#4

Merged
resmo merged 1 commit intomasterfrom
feature/output
May 30, 2020
Merged

consolidate options to global options#4
resmo merged 1 commit intomasterfrom
feature/output

Conversation

@resmo
Copy link
Contributor

@resmo resmo commented May 28, 2020

In this PR I move the common options such as --api-token to the cli group, as a consequence the CLI syntax slightly change from

cloudscale-cli server ---api-token <token> create ...
to
cloudscale-cli --api-token <token> server create

which actually makes a lot more "sense" because, these options are not specific to the server resource.

Further the version options is removed and replaced by click internal version option but had to change it to--version arg (I tried it with version but click is not happy).

A refactoring was done in commands,_init__ where I moved the functions to a new CloudscaleCommand wrapper class. This allowed to easily implement the --output option and I did it along (but I have some ideas to make it more generic and add probably add yaml and toml output.)

With the refactoring in place, the command group files become very slick, only a resource name for the attribute in the cloudscale lib cloudscale.<resource_name> is necessary and some headers for the table output.

import click

@click.group()
@click.pass_context
def flavor(ctx):
    ctx.obj.cloud_resource_name = "flavor"
    ctx.obj.headers = [
        'name',
        'vcpu_count',
        'memory_gb',
        'slug',
        'zones',
    ]

@flavor.command("list")
@click.pass_obj
def cmd_list(cloudscale):
    cloudscale.cmd_list()

Test coverage is 99% (seems the github actions don't run, cloud you check, I don't have access).

@resmo resmo added the enhancement New feature or request label May 28, 2020
@resmo resmo requested a review from gaudenz May 28, 2020 22:20
implements output option
@resmo resmo force-pushed the feature/output branch from e972a20 to b36c894 Compare May 28, 2020 22:26
This was referenced May 29, 2020
@resmo resmo merged commit 8c92d23 into master May 30, 2020
@resmo resmo deleted the feature/output branch May 30, 2020 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant