Skip to content

Conversation

@lallevato-lm
Copy link
Contributor

Description

Adds a valid args autocomplete function to bomctl for cached document IDs and aliases. The script to enable this completion can be created with bomctl completion bash (or whatever your shell is).

Fixes #66

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

lallevato-lm and others added 2 commits December 10, 2024 12:09
Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
@lallevato-lm lallevato-lm requested a review from a team as a code owner December 10, 2024 23:04
@lallevato-lm lallevato-lm self-assigned this Dec 10, 2024
lallevato-lm and others added 5 commits December 11, 2024 08:32
Co-authored-by: jhoward-lm <140011346+jhoward-lm@users.noreply.github.com>
Signed-off-by: Luke Allevato <165693161+lallevato-lm@users.noreply.github.com>
Co-authored-by: jhoward-lm <140011346+jhoward-lm@users.noreply.github.com>
Signed-off-by: Luke Allevato <165693161+lallevato-lm@users.noreply.github.com>
Co-authored-by: jhoward-lm <140011346+jhoward-lm@users.noreply.github.com>
Signed-off-by: Luke Allevato <165693161+lallevato-lm@users.noreply.github.com>
Co-authored-by: jhoward-lm <140011346+jhoward-lm@users.noreply.github.com>
Signed-off-by: Luke Allevato <165693161+lallevato-lm@users.noreply.github.com>
Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
@ashearin ashearin requested a review from jhoward-lm December 11, 2024 22:03
@jhoward-lm
Copy link
Contributor

jhoward-lm commented Dec 14, 2024

Edit: disregard, handled in #240

We should also add flag completions for flags like --format and --encoding

In the link PR branch, I've refactored flags like those that consist of a static set of choices, so keep that in mind. For the --type argument to link, this works:

	cobra.CheckErr(linkCmd.RegisterFlagCompletionFunc("type",
		func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
			return typeChoice.choices, cobra.ShellCompDirectiveDefault
		},
	))

where typeChoice.choices is equivalent to []string{"node", "document"}

Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
@jhoward-lm
Copy link
Contributor

jhoward-lm commented Dec 16, 2024

Just curious, what happens if you delete the database file before attempting to [tab][tab]? Or if you specify a different location for the database file using --cache-dir or the BOMCTL_CACHE_DIR environment variable?

Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
@jhoward-lm
Copy link
Contributor

Just curious, what happens if you delete the database file before attempting to [tab][tab]? Or if you specify a different location for the database file using --cache-dir or the BOMCTL_CACHE_DIR environment variable?

Had a couple ideas for a possible (and maybe only partial) solution using viper:

  • Try checking the value of the --cache-dir flag dynamically by using viper.GetString("cache_dir") to see if it's already captured by default before execution. It should at least have the value of BOMCTL_CACHE_DIR if it's already set in the environment
  • If that doesn't work, try setting the viper cache_dir config value by either:
    • updating the initCache function to set it by checking the command string for the value captured by --cache-dir[= ](.*) (doesn't have to be regex, just as an example)
    • adding an autocomplete function for --cache-dir that basically just does normal filesystem completions but also runs viper.Set("cache_dir", ...)

If nothing in the second option works, I think the first is probably good enough for now

Signed-off-by: lallevato-lm <luke.d.allevato@lmco.com>
Copy link
Contributor

@jhoward-lm jhoward-lm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@ashearin ashearin merged commit 3b7b3c0 into bomctl:main Dec 16, 2024
8 checks passed
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.

Autocompletion for repositories/aliases/etc

3 participants