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

ceph: bash auto complete for CLI based on mon command descriptions #7693

Merged
merged 2 commits into from Apr 3, 2016

Conversation

aclamk
Copy link
Contributor

@aclamk aclamk commented Feb 18, 2016

This is not bind to bash yet. Use as 'ceph --comp osd ls'.
Able to fulfill commands as well as print command line help, when matching is complete.
This is required step before adding hinting of string values, eg. pool names.
Signed-off-by: Adam Kupczyk(a.kupczyk@mirantis.com)

@tchaikov
Copy link
Contributor

@aclamk Adam, i assume that this pr supersedes #6264, am i right?

@aclamk
Copy link
Contributor Author

aclamk commented Feb 18, 2016

@tchaikov Yes, #6264 is no longer useful.

if not matches:
continue

if j < len(sig) and len(args)>0:
Copy link
Contributor

Choose a reason for hiding this comment

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

@aclamk could you run this script through pep8? i see some of your change does not follow it.

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 will.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay. fwiw, you can install it using pip install pep8.

@tchaikov
Copy link
Contributor

@aclamk and you might need to revise your commit message with more concise title and a Signed-off-by line, see https://github.com/ceph/ceph/blob/master/SubmittingPatches.rst#signing-contributions

@liewegas
Copy link
Member

@aclamk do you mind rebasing this on master to resolve the conflict? thanks!

@liewegas
Copy link
Member

2016-03-22T07:24:07.627 INFO:teuthology.orchestra.run.smithi024.stderr: File "/bin/ceph", line 523
2016-03-22T07:24:07.627 INFO:teuthology.orchestra.run.smithi024.stderr: print '\n'.join(sorted(set(comps)))
2016-03-22T07:24:07.628 INFO:teuthology.orchestra.run.smithi024.stderr: ^
2016-03-22T07:24:07.628 INFO:teuthology.orchestra.run.smithi024.stderr:SyntaxError: invalid syntax

if match_count == 1 and len(comps) == 0:
# only one command matched and no hints yet => add help
comps = comps + [' ', '#'+match_cmd['help']]
print '\n'.join(sorted(set(comps)))
Copy link
Contributor

Choose a reason for hiding this comment

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

@aclamk might need to fix this.

else:
# successfully matched all - except last one - arguments
if j < len(sig) and len(args) > 0:
comps = comps + sig[j].complete(args[-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

could also put

comps += sig[j].complete(args[-1])

@tchaikov
Copy link
Contributor

@aclamk could you please add the bind to bash in "src/bash_completion/ceph", so we can include this feature in jewel?

# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software
# Foundation. See file COPYING.
# Foundation.
Copy link
Contributor

Choose a reason for hiding this comment

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

trailing space.

@tchaikov
Copy link
Contributor

@aclamk could you

  • add your "Signed-off-by" to your commit of 4bffbd3, "git commit -s" can do this for you also.
  • prefix the title of it with "bash_completion: "

?

or you could just squash it into the previous one.

@@ -512,9 +512,9 @@ def complete(sigdict, args, target):
else:
# successfully matched all - except last one - arguments
if j < len(sig) and len(args) > 0:
comps = comps + sig[j].complete(args[-1])
comps += sig[j].complete(args[-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

better off moving this change to the previous commit.

#skip this word if it is option
if [[ " ${options_noarg} " =~ " ${COMP_WORDS[i]} " ]] ; then continue; fi
#skip this word and next if it is option with arg
if [[ " ${options_arg} " =~ " ${COMP_WORDS[i]} " ]] ; then ((i++)); continue; fi
Copy link
Contributor

Choose a reason for hiding this comment

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

could remove the extra spaces? or break the if block into multiple lines.

@tchaikov
Copy link
Contributor

tested, works great!

lgtm apart from some formatting nits.

Now logic moved from bash to python.
Not bind to bash yet. Use as 'ceph --comp osd ls'.
Able to fulfill commands and print command line help.
Signed-off-by: Adam Kupczyk <a.kupczyk@mirantis.com>
@aclamk aclamk force-pushed the auto_complete_python branch 2 times, most recently from bc8c3bf to f9591f5 Compare March 31, 2016 08:09
@aclamk
Copy link
Contributor Author

aclamk commented Mar 31, 2016

@tchaikov: added signed-off, reformatted bash code, removed spaces. Please take a look and comment.

@tchaikov
Copy link
Contributor

@aclamk could you remove the heading spaces in the commit message of f9591f5

    Signed-off-by: Adam Kupczyk <a.kupczyk@mirantis.com>

and add a prefix of "bash_completion: " to the first line of it. and the commit message is not accurate, imho. we have a bash-completion for ceph CLI, but your change improves it by using the updated "ceph --completion".

Signed-off-by: Adam Kupczyk <a.kupczyk@mirantis.com>
@aclamk
Copy link
Contributor Author

aclamk commented Mar 31, 2016

@tchaikov: Its a pleasure to polish out work with you.

@tchaikov
Copy link
Contributor

lgtm

@tchaikov
Copy link
Contributor

tchaikov commented Apr 1, 2016

my pleasure also! =)

@liewegas liewegas changed the title Auto complete feature for CLI. Now logic moved from bash to python. ceph: bash auto complete for CLI based on mon command descriptions Apr 3, 2016
@liewegas liewegas merged commit dac9ad3 into ceph:master Apr 3, 2016
@@ -1,73 +1,50 @@
#
# Ceph - scalable distributed file system
#
# Copyright (C) 2011 Wido den Hollander <wido@widodh.nl>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you delete that copyright ?

ErwanAliasr1 pushed a commit to ErwanAliasr1/ceph that referenced this pull request Apr 4, 2016
Since the merge of pr ceph#7693, 'ceph <command>' to get the help is invalid.
As a result, 'test/cephtool-test-mon.sh' test was broken

This patch simply change the 'ceph <command>' by a 'ceph --help <command>'

Since this change the test is passing again.

Signed-off-by: Erwan Velu <erwan@redhat.com>
ErwanAliasr1 pushed a commit to ErwanAliasr1/ceph that referenced this pull request Apr 4, 2016
Since the merge of pr ceph#7693, 'ceph command' to get the help is invalid.
As a result, 'test/cephtool-test-mon.sh' test was broken

This patch simply change the 'ceph command' by a 'ceph --help command'

Since this change the test is passing again.

Signed-off-by: Erwan Velu <erwan@redhat.com>
@aclamk
Copy link
Contributor Author

aclamk commented Apr 4, 2016

@ErwanAliasr1

  1. I deleted copyright intentionally
  2. I was thinking that after change of this magnitude (actually all content new) it would be unfair to leave original copyright
  3. I didnt put my copyright because I felt more along copyleft

@ErwanAliasr1
Copy link
Contributor

@aclamk ok make sense.

jjhuo pushed a commit to jjhuo/ceph that referenced this pull request Apr 5, 2016
Since the merge of pr ceph#7693, 'ceph command' to get the help is invalid.
As a result, 'test/cephtool-test-mon.sh' test was broken

This patch simply change the 'ceph command' by a 'ceph --help command'

Since this change the test is passing again.

Signed-off-by: Erwan Velu <erwan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants