Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow specifying default columns for each sub command #423

Closed
wants to merge 4 commits into from

Commits on Nov 17, 2022

  1. allow sorting to be configured globally (closes hetznercloud#418)

    I am a heavy user of the hcloud-cli. However, I really don't like the
    default sorting by server-id, and would prefer sorting by age
    (see hetznercloud#417/hetznercloud#420) or name.
    
    Currently, I always type `hcloud server list -s name` to sort by name.
    
    since the `-s` flag is part of the `list` subcommand and not the `hcloud`
    base command (like in many other software that makes use of the Cobra
    framework), I cannot simply `alias hcloud-"hcloud -s name"` in my shell
    to default the sorting to "by name".
    
    This commit adds a `[defaults]` section to the config toml which allows
    to override the default sorting behavior for individual `hcloud`
    subcommands.
    
    The following behavior is used to determine the sorting-order
    
    | config file | flag    | result               |
    |-------------|---------|----------------------|
    | not-set     | not-set | sort by id (default) |
    | not-set     | set     | sort by flag value   |
    | set         | not-set | sort by config value |
    | set         | set     | sort by flag value   |
    cedi committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    b07b039 View commit details
    Browse the repository at this point in the history
  2. fix unit-tests

    cedi committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    1da959a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    350d701 View commit details
    Browse the repository at this point in the history
  4. allow specifying default columns for each sub command

    I am a heavy user of the hcloud-cli. However, I usually change the columns that are displayed and don't like the default and would prefer specifying the default columns used in the config file.
    Note: This PR adds on top of the work of hetznercloud#421 and should not be merged
    before hetznercloud#421.
    
    Currently, I always type `hcloud server list -o 'columns=name,status,ipv6,private_net'` to only get the columns that I'm interested in
    
    since the `-o` flag is part of the `list` subcommand and not the `hcloud` base command (like in many other software that makes use of the Cobra framework),
    I cannot simply `alias hcloud-"hcloud -o 'columns='"` in my shell to default the columns.
    
    This commit adds a `[defaults]` section to the config toml which allows to override the default sorting behavior for individual `hcloud` subcommands.
    
    The following behavior is used to determine the displayed columns
    
    | config file | flag    | result                      |
    |-------------|---------|-----------------------------|
    | not-set     | not-set | display default columns     |
    | not-set     | set     | display -o flag columns     |
    | set         | not-set | display config file columns |
    | set         | set     | display -o flag columns     |
    cedi committed Nov 17, 2022
    Configuration menu
    Copy the full SHA
    8d0d788 View commit details
    Browse the repository at this point in the history