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

no autocomplete for <PATH> on CLI commands #352

Closed
ghostsquad opened this issue Aug 20, 2020 · 8 comments · Fixed by #357
Closed

no autocomplete for <PATH> on CLI commands #352

ghostsquad opened this issue Aug 20, 2020 · 8 comments · Fixed by #357
Labels
kind/bug Something isn't working

Comments

@ghostsquad
Copy link

I cannot autocomplete paths on commands such as tk diff <PATH>

@issue-label-bot issue-label-bot bot added the kind/bug Something isn't working label Aug 20, 2020
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label kind/bug to this issue, with a confidence of 0.70. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@malcolmholmes
Copy link
Collaborator

@ghostsquad how are you configuring autocomplete?

@ghostsquad
Copy link
Author

I'm using ZSH. For reference, the problem appears to be if I've nested my environments, and if I'm running tk from a more top-level directory:

example of the location of the spec.json:

./deploy/kubernetes/environments/development/spec.json

if I try to run tk diff from ./ (being the root of my repo) it doesn't try to autocomplete the environments or let me specify the path to the environment.

However, if my PWD is ./deploy/kubernetes/environments then it does autocomplete development

@Duologic
Copy link
Member

I have been annoyed by that too, if I'm one directory above the Tanka root, then the directory autocomplete just doesn't respond while technically it will just work.

@sh0rez
Copy link
Member

sh0rez commented Aug 21, 2020

Let me give some technical background on this.

Tanka implements its own bash completion handler in Go, which allows us to use arbitrarily complex computation to generate those results. ZSH and Fish use Bash compat mode and should just work as well. The tk completion command enables the feature for all locally installed shells.

Bespoke directory completion does not actually suggest directories, but instead it uses the code that powers tk env list to find environments, starting from the current directory. This code however requires a jsonnetfile.json in the current or enclosing folders.

When being just one level outside of the this is no longer satisfied and our code returns an empty list, which effectively means no completion.

I see two ways forward here:

  1. We could use the last full directory of the already supplied argument to run the search on, instead of pwd (in findBaseDirs):

    tanka/cmd/tk/args.go

    Lines 8 to 16 in fdf0ca1

    var workflowArgs = cli.Args{
    Validator: cli.ValidateExact(1),
    Predictor: cli.PredictFunc(func(complete.Args) []string {
    if dirs := findBaseDirs(); len(dirs) != 0 {
    return dirs
    }
    return []string{""}
    }),
    }

  2. We could fallback to the regular directory completion in case environment completion is not possible.

No. 2 is certainly simpler and straightforward to implement.

@ghostsquad
Copy link
Author

ghostsquad commented Aug 21, 2020

  1. since spec.json and main.jsonnet are required files (for now, see how to use a kube config context instead of ApiServer URL? #351) - you could crawl the directory structure (say up to 10 directories deep), looking for folders that contain those 2 files?

@Duologic
Copy link
Member

I'd be all for 2., my general expectation is that I can tab complete from current working dir to wherever the environment exists.

@ghostsquad
Copy link
Author

You da best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants