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

Improved alias support #184

Merged
merged 6 commits into from
Oct 15, 2022
Merged

Improved alias support #184

merged 6 commits into from
Oct 15, 2022

Conversation

reubenmiller
Copy link
Owner

Improved alias usage to include the following new usability improvements:

  • Tab completion for flags
  • Improved error messages

Examples

The following examples use the mo alias, which is included by default. The alias pretty prints a managed object given an id.

# create alias
c8y alias set mo "inventory get --view off --output json --id '\$1'"

# Usage
c8y mo 1234

Tab completion for flags

Tab completion of flags on aliases makes it easier to extend the alias at runtime to make them more flexible.

c8y mo 1234 --<TAB><TAB>
--skipChildrenNames  -- Don't include the child devices names in the response. 
--withChildren       -- Determines if children with ID and name should be returned when fetching the managed object.
--withParents        -- include a flat list of all parents and grandparents of the given object

Improved alias error message

If the alias expects a positional argument, then the user will presented with an error message about why it failed.

c8y mo        
2022-10-15T19:42:18.410+0200    ERROR   Could not expand aliases. not enough arguments for alias. Expected 1, got 0

  Expanded alias: inventory get --view off --output json --id '$1' 

  Tip: Aliases expect the positional arguments to be given before other flags

Alias now support piped input

Use the - character to denote piped input. This was actually introduced in 2.16.0 but it was not mentioned in the release notes.

echo 12345 | c8y mo -

@reubenmiller reubenmiller merged commit 31b5c36 into v2 Oct 15, 2022
@reubenmiller reubenmiller deleted the feat/alias-flag-completion branch October 15, 2022 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant