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

Add completions for fabric(deploy-tool) #4153

Closed
wants to merge 5 commits into from

Conversation

tamanugi
Copy link
Contributor

Description

Add fab completions
http://www.fabfile.org/

example

# fabfile.py
# -*- encoding:utf-8 -*-
from fabric.api import *

def hello_world():
    print "hello"

def hoge():
    """
    print hogehoge
    """
    print "hogehoge"

fab -l is displayed as follows:

$ fab -l
Available commands:

    hello_world
    hoge         print hogehoge

so fab-command completions as follows:

$fab <TAB>                                                                          
hello_world  (No description)  hoge  (print hogehoge)

if test -n "$_matched"
set -l _task_name $_matched[2]
set -l _task_desc $_matched[3]
test -n "$task_desc"; or set -l _task_desc "No description"
Copy link
Member

Choose a reason for hiding this comment

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

Please just leave the description empty if there is none.

set -l _matched (string match -r "^ +([^ ]*) *([^ ]?.*)" $task)

if test -n "$_matched"
set -l _task_name $_matched[2]
Copy link
Member

Choose a reason for hiding this comment

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

You know... 13 hours ago I would have told you that this could lead to an "Array index out of bounds" error. But then we merged #4151.

😺

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😸

I remove if test -n $_matched
and I confirmed that it works without problems!!

@@ -0,0 +1,75 @@
# tasks
for task in (fab -l)
Copy link
Member

Choose a reason for hiding this comment

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

This should be put into a function that is then called via complete -c fab -a '(thatfunction)'.

Otherwise these won't change if anything changes about the output (e.g. because you've switched to using a different file).

set -l _task_name $_matched[2]
set -l _task_desc $_matched[3]
test -n "$task_desc"; or set -l _task_desc "No description"
complete -f -c fab -a "$_task_name" -d "$_task_desc"
Copy link
Member

Choose a reason for hiding this comment

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

Once this is in a function, you can do `printf "%s\t%s\n" "$_task_name" "$_task_desc" - the part after the tab character (\t) will be used as the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I wanted to know!!!!

improved 😄

Move for ~ end to function __fish_complete_fab_tasks .
And
Change like following:
complete -x -c fab -a "(__fish_complete_fab_tasks)"

complete -x -c fab -s g -l gateway -a "
(__fish_print_hostnames)
(
echo (commandline -ct)|sed -ne 's/\(.*@\).*/\1/p'
Copy link
Member

Choose a reason for hiding this comment

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

This should be rewritten to use string replace.

Something like commandline -ct | string replace -r '(.*@).*' '$1' (the echo is superfluous).

Copy link
Member

Choose a reason for hiding this comment

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

Also, you're using this three times here (and we also do it in a few completions, including ssh and mosh), so a helper function would be adequate. If you'd like, put it into "share/functions/__fish_complete_user_at_host.fish" or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed
I added helper function __fish_complete_user_at_host.fish.
Can you confirm that I am not confident 😓

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it appears to work.

complete -c fab -l colorize-errors -d "Color error output"
complete -c fab -s D -l disable-known-host -d "do not load user known_hosts file"
complete -c fab -s e -l eagerly-disconnect -d "disconnect from hosts as soon as possible"
complete -x -c fab -s f -l fabfile -d "python module file to import, e.g. '../other.py'"
Copy link
Member

Choose a reason for hiding this comment

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

This should actually use file completions, so remove the "-x".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.
This option required argument, so added "-r" option.
correct??

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that should be okay.

complete -x -c fab -l show -d "comma-separated list of output levels to show"
complete -c fab -l skip-bad-hosts -d "skip over hosts that can't be reached"
complete -c fab -l skip-unknown-tasks -d "skip over unknown tasks"
complete -x -c fab -l ssh-config-path -d "Path to SSH config file"
Copy link
Member

Choose a reason for hiding this comment

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

Also remove "-x".

@faho faho self-assigned this Jun 22, 2017
@faho
Copy link
Member

faho commented Jul 5, 2017

Merged as 70c9d78..6b92f83. Sorry for the delay!

@faho faho closed this Jul 5, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants