If implemented, there should be a section fro this in the coding guidelines, and every new command line switch should follow thsoe guidelines for inclusion in the bash-completion file.
Not sure I understand - is this about tab completion on instance names or something else?
(In reply to comment #1) > Not sure I understand - is this about tab completion on instance names or > something else? Its about tab completion of instances and all switches and parameters (providing a bash-completion script for the job). For the job I'll need help on the possible combination of switches.
Created attachment 20743 [details] [review] Bug 10003: bash-completion for koha-list and some other script This is an initial commit submitted for peer review. It implements bash-completion for the following commands: - koha-list - koha-enable - koha-disable - koha-email-enable - koha-email-disable - koha-enable-sip - koha-start-sip - koha-restart-sip - koha-stop-sip - koha-start-zebra - koha-stop-zebra - koha-restart-zebra It is implemented in a way that it removes already used or mutually exclusive parameters (instance names, option switches). I already have written completion for other (more complex) commands, But I belive a simpler patch is better to start with. IMPORTANT: this patch relies on having the koha-list command available in the path. Also 10622 is needed for the SIP-related option switches. To test: - Make sure you have bash-completion installed and enabled (IRC might help us if you encounter problems). - Apply the patch. Option 1: - Pick the debian/koha-common.bash-completion file and do $ cp debian/koha-common.bash-completion /etc/bash_completion.d/koha-common - Open a new bash shell (I do it opening a new terminal on my Ubuntu box). - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Option 2: - run: $ . debian/koha-common.bash-completion - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Tests: - Some koha-list option switches are mutually exclusive, -h should be available in any context - koha-enable should only autocomplete disabled instances - koha-disable should only autocomplete enabled instances - koha-email-enable should only autocomplete email-disabled instances - koha-email-disable should only autocomplete email-enabled instances - koha-*-zebra scripts should only autocomplete enabled instances. - koha-*-sip scripts should only autocomplete sip-enabled instances. Regards To+ Note: writing bash-completion routines is a bit hacky, I tried to make it the simplest way I could. Your comments are welcome. Sponsored-by: Universidad Nacional de Cordoba
I have built a package for testing purposes. It's bug 10622 patches + this patch on top of master. It can be found here: http://es.koha-community.org/kc_files/koha-common_3.13-1~git+20130830120021.1417289e_all.deb
Patch applied cleanly, go forth and signoff
Created attachment 22609 [details] [review] Bug 10003: bash-completion for koha-list and some other script This is an initial commit submitted for peer review. It implements bash-completion for the following commands: - koha-list - koha-enable - koha-disable - koha-email-enable - koha-email-disable - koha-enable-sip - koha-start-sip - koha-restart-sip - koha-stop-sip - koha-start-zebra - koha-stop-zebra - koha-restart-zebra It is implemented in a way that it removes already used or mutually exclusive parameters (instance names, option switches). I already have written completion for other (more complex) commands, But I belive a simpler patch is better to start with. IMPORTANT: this patch relies on having the koha-list command available in the path. Also 10622 is needed for the SIP-related option switches. To test: - Make sure you have bash-completion installed and enabled (IRC might help us if you encounter problems). - Apply the patch. Option 1: - Pick the debian/koha-common.bash-completion file and do $ cp debian/koha-common.bash-completion /etc/bash_completion.d/koha-common - Open a new bash shell (I do it opening a new terminal on my Ubuntu box). - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Option 2: - run: $ . debian/koha-common.bash-completion - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Tests: - Some koha-list option switches are mutually exclusive, -h should be available in any context - koha-enable should only autocomplete disabled instances - koha-disable should only autocomplete enabled instances - koha-email-enable should only autocomplete email-disabled instances - koha-email-disable should only autocomplete email-enabled instances - koha-*-zebra scripts should only autocomplete enabled instances. - koha-*-sip scripts should only autocomplete sip-enabled instances. Regards To+ Note: writing bash-completion routines is a bit hacky, I tried to make it the simplest way I could. Your comments are welcome. Sponsored-by: Universidad Nacional de Cordoba
After finding that filer vs. filter typo, I had hopes for it working. However, this is some of my testing output: mtompset@ubuntu:~$ koha-list library mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$ sudo koha-disable grep: /etc/apache2/sites-available/library: Permission denied library grep: /etc/apache2/sites-available/library: Permission denied * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ] mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ sudo koha-disable library Instance library already disabled. mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ koha-list --enabled grep: /etc/apache2/sites-available/library: Permission denied library mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$ koha-list --disabled grep: /etc/apache2/sites-available/library: Permission denied mtompset@ubuntu:~$
root@ubuntu:~# koha-enable --help Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. PATTERN is, by default, a basic regular expression (BRE). Example: grep -i 'hello world' menu.h main.c Regexp selection and interpretation: -E, --extended-regexp PATTERN is an extended regular expression (ERE) -F, --fixed-strings PATTERN is a set of newline-separated fixed strings -G, --basic-regexp PATTERN is a basic regular expression (BRE) -P, --perl-regexp PATTERN is a Perl regular expression -e, --regexp=PATTERN use PATTERN for matching -f, --file=FILE obtain PATTERN from FILE -i, --ignore-case ignore case distinctions -w, --word-regexp force PATTERN to match only whole words -x, --line-regexp force PATTERN to match only whole lines -z, --null-data a data line ends in 0 byte, not newline Miscellaneous: -s, --no-messages suppress error messages -v, --invert-match select non-matching lines -V, --version print version information and exit --help display this help and exit --mmap ignored for backwards compatibility Output control: -m, --max-count=NUM stop after NUM matches -b, --byte-offset print the byte offset with output lines -n, --line-number print line number with output lines --line-buffered flush output on every line -H, --with-filename print the file name for each match -h, --no-filename suppress the file name prefix on output --label=LABEL use LABEL as the standard input file name prefix -o, --only-matching show only the part of a line matching PATTERN -q, --quiet, --silent suppress all normal output --binary-files=TYPE assume that binary files are TYPE; TYPE is `binary', `text', or `without-match' -a, --text equivalent to --binary-files=text -I equivalent to --binary-files=without-match -d, --directories=ACTION how to handle directories; ACTION is `read', `recurse', or `skip' -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is `read' or `skip' -R, -r, --recursive equivalent to --directories=recurse --include=FILE_PATTERN search only files that match FILE_PATTERN --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN --exclude-from=FILE skip files matching any file pattern from FILE --exclude-dir=PATTERN directories that match PATTERN will be skipped. -L, --files-without-match print only names of FILEs containing no match -l, --files-with-matches print only names of FILEs containing matches -c, --count print only a count of matching lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name Context control: -B, --before-context=NUM print NUM lines of leading context -A, --after-context=NUM print NUM lines of trailing context -C, --context=NUM print NUM lines of output context -NUM same as --context=NUM --color[=WHEN], --colour[=WHEN] use markers to highlight the matching strings; WHEN is `always', `never', or `auto' -U, --binary do not strip CR characters at EOL (MSDOS) -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS) `egrep' means `grep -E'. `fgrep' means `grep -F'. Direct invocation as either `egrep' or `fgrep' is deprecated. With no FILE, or when FILE is -, read standard input. If less than two FILEs are given, assume -h. Exit status is 0 if any line was selected, 1 otherwise; if any error occurs and -q was not given, the exit status is 2. Report bugs to: bug-grep@gnu.org GNU Grep home page: <http://www.gnu.org/software/grep/> General help using GNU software: <http://www.gnu.org/gethelp/> Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. PATTERN is, by default, a basic regular expression (BRE). Example: grep -i 'hello world' menu.h main.c Regexp selection and interpretation: -E, --extended-regexp PATTERN is an extended regular expression (ERE) -F, --fixed-strings PATTERN is a set of newline-separated fixed strings -G, --basic-regexp PATTERN is a basic regular expression (BRE) -P, --perl-regexp PATTERN is a Perl regular expression -e, --regexp=PATTERN use PATTERN for matching -f, --file=FILE obtain PATTERN from FILE -i, --ignore-case ignore case distinctions -w, --word-regexp force PATTERN to match only whole words -x, --line-regexp force PATTERN to match only whole lines -z, --null-data a data line ends in 0 byte, not newline Miscellaneous: -s, --no-messages suppress error messages -v, --invert-match select non-matching lines -V, --version print version information and exit --help display this help and exit --mmap ignored for backwards compatibility Output control: -m, --max-count=NUM stop after NUM matches -b, --byte-offset print the byte offset with output lines -n, --line-number print line number with output lines --line-buffered flush output on every line -H, --with-filename print the file name for each match -h, --no-filename suppress the file name prefix on output --label=LABEL use LABEL as the standard input file name prefix -o, --only-matching show only the part of a line matching PATTERN -q, --quiet, --silent suppress all normal output --binary-files=TYPE assume that binary files are TYPE; TYPE is `binary', `text', or `without-match' -a, --text equivalent to --binary-files=text -I equivalent to --binary-files=without-match -d, --directories=ACTION how to handle directories; ACTION is `read', `recurse', or `skip' -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is `read' or `skip' -R, -r, --recursive equivalent to --directories=recurse --include=FILE_PATTERN search only files that match FILE_PATTERN --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN --exclude-from=FILE skip files matching any file pattern from FILE --exclude-dir=PATTERN directories that match PATTERN will be skipped. -L, --files-without-match print only names of FILEs containing no match -l, --files-with-matches print only names of FILEs containing matches -c, --count print only a count of matching lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name Context control: -B, --before-context=NUM print NUM lines of leading context -A, --after-context=NUM print NUM lines of trailing context -C, --context=NUM print NUM lines of output context -NUM same as --context=NUM --color[=WHEN], --colour[=WHEN] use markers to highlight the matching strings; WHEN is `always', `never', or `auto' -U, --binary do not strip CR characters at EOL (MSDOS) -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS) `egrep' means `grep -E'. `fgrep' means `grep -F'. Direct invocation as either `egrep' or `fgrep' is deprecated. With no FILE, or when FILE is -, read standard input. If less than two FILEs are given, assume -h. Exit status is 0 if any line was selected, 1 otherwise; if any error occurs and -q was not given, the exit status is 2. Report bugs to: bug-grep@gnu.org GNU Grep home page: <http://www.gnu.org/software/grep/> General help using GNU software: <http://www.gnu.org/gethelp/> grep: /etc/apache2/sites-available/--help: No such file or directory Instance --help already enabled. Not really a bug, but definitely a weird side-effect.
root@ubuntu:~# koha-stop-zebra instance2 Stopping Zebra server for instance2 root@ubuntu:~# koha-stop-zebra instance2 Zebra already stopped for instance instance2. root@ubuntu:~# koha-stop-zebra instance2 Zebra already stopped for instance instance2. The tab completion came up with instance2 even though it was stopped already. Hmmm... my koha-restart-sip doesn't exist, I think that was bug 10622. Perhaps I built my .deb before including 10622. Any other tests I had issues with were NOT tab completion issues, but rather behaviour issues (--help vs. no parameter, what does disable really mean, feedback vs. no feedback).
(In reply to M. Tompsett from comment #10) > root@ubuntu:~# koha-stop-zebra instance2 > Stopping Zebra server for instance2 > root@ubuntu:~# koha-stop-zebra instance2 > Zebra already stopped for instance instance2. > root@ubuntu:~# koha-stop-zebra instance2 > Zebra already stopped for instance instance2. > > The tab completion came up with instance2 even though it was stopped already. > > Hmmm... my koha-restart-sip doesn't exist, I think that was bug 10622. > Perhaps I built my .deb before including 10622. > > Any other tests I had issues with were NOT tab completion issues, but rather > behaviour issues (--help vs. no parameter, what does disable really mean, > feedback vs. no feedback). All this is intended. tab completion just shows valid parameters for the command. You can call any of those koha-*-action commands with instances for such the task is not running and the result is that you got. Those scripts just check the instance is enabled. You shouldn't ask tab completion to provide things the commands themselves don't provide. Please don't paste the output of the grep command help, it just makes this bug unreadable.
Have you fixed the issue with tab completion failing for non-root users?
Created attachment 23701 [details] [review] Bug 10003: (followup) use sudo to get the instances list Te only way of using the koha-* commands is using sudo. The only way to get the list of enabled instances and other insight information of the instances is through the use of sudo. This followup makes the tab-completion bash script use sudo for calling 'koha-list' so it can read teh relevant data. The drawback of this approach is that the user will be prompted for password the first time he/she presses the tab key twice (triggering tab-completion). I see no problem with that. And is the only option available, apart from the setuid one. Which I don't like. Regards To+ Sponsored-by: Universidad Nacional de Cordoba
Created attachment 26179 [details] [review] Bug 10003: bash-completion for koha-list and some other script This is an initial commit submitted for peer review. It implements bash-completion for the following commands: - koha-list - koha-enable - koha-disable - koha-email-enable - koha-email-disable - koha-enable-sip - koha-start-sip - koha-restart-sip - koha-stop-sip - koha-start-zebra - koha-stop-zebra - koha-restart-zebra It is implemented in a way that it removes already used or mutually exclusive parameters (instance names, option switches). I already have written completion for other (more complex) commands, But I belive a simpler patch is better to start with. IMPORTANT: this patch relies on having the koha-list command available in the path. Also 10622 is needed for the SIP-related option switches. To test: - Make sure you have bash-completion installed and enabled (IRC might help us if you encounter problems). - Apply the patch. Option 1: - Pick the debian/koha-common.bash-completion file and do $ cp debian/koha-common.bash-completion /etc/bash_completion.d/koha-common - Open a new bash shell (I do it opening a new terminal on my Ubuntu box). - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Option 2: - run: $ . debian/koha-common.bash-completion - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Tests: - Some koha-list option switches are mutually exclusive, -h should be available in any context - koha-enable should only autocomplete disabled instances - koha-disable should only autocomplete enabled instances - koha-email-enable should only autocomplete email-disabled instances - koha-email-disable should only autocomplete email-enabled instances - koha-*-zebra scripts should only autocomplete enabled instances. - koha-*-sip scripts should only autocomplete sip-enabled instances. Regards To+ Note: writing bash-completion routines is a bit hacky, I tried to make it the simplest way I could. Your comments are welcome. Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org>
Created attachment 26180 [details] [review] Bug 10003: (followup) use sudo to get the instances list Te only way of using the koha-* commands is using sudo. The only way to get the list of enabled instances and other insight information of the instances is through the use of sudo. This followup makes the tab-completion bash script use sudo for calling 'koha-list' so it can read teh relevant data. The drawback of this approach is that the user will be prompted for password the first time he/she presses the tab key twice (triggering tab-completion). I see no problem with that. And is the only option available, apart from the setuid one. Which I don't like. Regards To+ Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org>
Very useful and nice addition to our packages, IMHO :-)
Created attachment 26476 [details] [review] Bug 10003: bash-completion for koha-list and some other script This is an initial commit submitted for peer review. It implements bash-completion for the following commands: - koha-list - koha-enable - koha-disable - koha-email-enable - koha-email-disable - koha-enable-sip - koha-start-sip - koha-restart-sip - koha-stop-sip - koha-start-zebra - koha-stop-zebra - koha-restart-zebra It is implemented in a way that it removes already used or mutually exclusive parameters (instance names, option switches). I already have written completion for other (more complex) commands, But I belive a simpler patch is better to start with. IMPORTANT: this patch relies on having the koha-list command available in the path. Also 10622 is needed for the SIP-related option switches. To test: - Make sure you have bash-completion installed and enabled (IRC might help us if you encounter problems). - Apply the patch. Option 1: - Pick the debian/koha-common.bash-completion file and do $ cp debian/koha-common.bash-completion /etc/bash_completion.d/koha-common - Open a new bash shell (I do it opening a new terminal on my Ubuntu box). - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Option 2: - run: $ . debian/koha-common.bash-completion - Type one of the listed commands... And repeatedly press <TAB>. - Enjoy, and signoff if you belive it is usable. Otherwise report back. Tests: - Some koha-list option switches are mutually exclusive, -h should be available in any context - koha-enable should only autocomplete disabled instances - koha-disable should only autocomplete enabled instances - koha-email-enable should only autocomplete email-disabled instances - koha-email-disable should only autocomplete email-enabled instances - koha-*-zebra scripts should only autocomplete enabled instances. - koha-*-sip scripts should only autocomplete sip-enabled instances. Regards To+ Note: writing bash-completion routines is a bit hacky, I tried to make it the simplest way I could. Your comments are welcome. Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Created attachment 26477 [details] [review] Bug 10003: (followup) use sudo to get the instances list Te only way of using the koha-* commands is using sudo. The only way to get the list of enabled instances and other insight information of the instances is through the use of sudo. This followup makes the tab-completion bash script use sudo for calling 'koha-list' so it can read teh relevant data. The drawback of this approach is that the user will be prompted for password the first time he/she presses the tab key twice (triggering tab-completion). I see no problem with that. And is the only option available, apart from the setuid one. Which I don't like. Regards To+ Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org> Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Pushed to master. Thanks, Tomás. However, I am not pushing the follow-up: I've never heard of any other package that prompts you for a sudo password just by hitting the tab key. It's one thing to do 'sudo foo', then get prompted for a password -- that's what you expect. But not for hitting the tab key.