Skip to content

Conversation

@DannyBen
Copy link
Member

@DannyBen DannyBen commented Sep 3, 2022

This change makes it so the returned completions will not include any flags (--flags) unless the input line ends with a -.

In other words, given this config:

# completely.yaml
mygit:
- --help
- --version
- status
- init
- commit

The new behavior will be:

$ completely test "mygit "
status
init
commit

$ completely test "mygit -"
--help
--version

instead of:

$ completely test "mygit "
status
init
commit
--help
--version

cc #32

def patterns!
config.map do |text, completions|
Pattern.new text, completions
Pattern.new text, completions, pattern_function_name
Copy link
Member Author

Choose a reason for hiding this comment

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

Pattern now receives a function name, which is the name of the helper filter function. It is used in Pattern#compgen to generate the compgen string which now calls a function rather than just using the string straight up.

fi
}

<%= function_name %>() {
Copy link
Member Author

Choose a reason for hiding this comment

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

The function at line 7 receives a space-delimited string of possible completions, and:

  1. returns the same string if the current word starts with a hyphen
  2. returns a new string without any --flags if the current word does not start with a hyphen

@@ -1,24 +1,32 @@
ftp:
Copy link
Member Author

Choose a reason for hiding this comment

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

Since completions are now returned differently if the input ends with a hyphen, this integration spec config was expanded to list both cases.

Copy link

@mrliptontea mrliptontea left a comment

Choose a reason for hiding this comment

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

I think this works, nice.

@DannyBen DannyBen merged commit bfb1017 into master Sep 4, 2022
@DannyBen DannyBen deleted the change/hide-flags branch September 4, 2022 06:02
@DannyBen
Copy link
Member Author

DannyBen commented Sep 4, 2022

Merged, will release later.
If you are using the ruby version (and not the docker) you can already test it if you wish.

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.

3 participants