[systemd-devel] [TOOL] Check-undocumented arguments and bash autocompletions

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Jan 28 20:34:43 PST 2015


On Sun, Jan 11, 2015 at 09:46:47PM +0100, Carlos Morata Castillo wrote:
> Hi,
> 
> I've updated the tool today to work with verbs and some cache issues.
Sorry for the delayed reply. This seems useful, to catch regressions,
and to see how much stuff is still undocumented.

> >./check-undocumented.sh -p hostnamectl
> Not standar hostnamectl.Update please.
> Updates needed in ../shell-completion/bash/hostnamectl
> ...Option not found: "--machine"
> ...Verb not found: "set-location"
It would be nice to turn this into a makefile target, like other tools...

> ------------------
> #!/bin/bash 
> #  This file is part of systemd.
> #
> #  Copyright 2015 Carlos Morata Castillo <cmc809 at inlumine.ual.es>
> #
> #  systemd is free software; you can redistribute it and/or modify it
> #  under the terms of the GNU Lesser General Public License as published by
> #  the Free Software Foundation; either version 2.1 of the License, or
> #  (at your option) any later version.
> #
> #  systemd is distributed in the hope that it will be useful, but
> #  WITHOUT ANY WARRANTY; without even the implied warranty of
> #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> #  Lesser General Public License for more details.
> #
> #  You should have received a copy of the GNU Lesser General Public License
> #  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> 
> #
> # Parse command line commands options and search for undocumented
> # options/commands in his manpage and bash autocompletion
> 
> #Version 0.1 Parse manpages and bash autocompletion options
> #Version 0.2 Parse manpages and bash autocompletion verbs/commands
> 
> __version=0.2
> MANPAGES=../man
> BASH_AUTO=../shell-completion/bash
> 
> function get_systemd_commands(){
> local regex
> regex='(root)?bin_PROGRAMS[[:space:]]?(\+?)=(.*)'
This should be supplied by make as commandline args, see dist-check-help
in Makefile.am.

> 
> grep -E $regex ../Makefile.am -A 20 | while read a; do 
> [[ $a =~ $regex ]] && echo ${BASH_REMATCH[3]}
> done
> }
> 
> function get_options(){
> local com args arg value
> com=$1
> [[ ! $com ]] && return
> hash $com 2>/dev/null || return 0
> 
> args=($($com -h))
> for arg in $(seq 0 $((${#args[@]}-1))); 
> do
>     value=${args[arg]}
>     if [[ $value == -* ]]; then
>         echo $value
>     fi
> done
> }

Hm, maybe simply use sed -n '/..../p' (or whatever the syntax is to
just print the matching pattern. We use sed during build, and it would
be more readable than the bash stuff.

> 
> function get_verbs(){
> local com regex_commands regex_verbs line arr found
> com="$1 -h"
> regex_commands='^(.*)Commands:$'
> regex_verbs='^([[:space:]]){1,2}([-[:alnum:]])(.*)'; 
> 
> while IFS= read -r line
> do
>     [[ "$line" =~ $regex_commands ]] && found=1 && continue
>     if [[ $found ]]; 
>     then
>         if [[ "$line" =~ $regex_verbs ]]; 
>         then
>             arr=(${line//[[:space:]]/ })
>             echo ${arr[0]}
>         fi
>     fi
> done < <($com)
> }
> 
> function filter(){
> local value ret
> value=$1
> ret="true"
> 
> #Shall it leave out -M and -H or not?
> [[ "$value" = "-h" || "$value" = "--help" 
> || "$value" = "-M" || "$value" = "-H" 
> || "$value" = "--version" ]] &&
>     ret="false"
> echo "$ret"
> }
That's a good question. It would be nice to process xml files after
processing xincludes, similarly to the python filters we have. So
this leads me to ask, whether it wouldn't be better to write this
as a python program... Might be way shorter in effect.

Zbyszek


More information about the systemd-devel mailing list