zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Andy Spencer <andy@pileus.org>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] Add completion for cpupower command
Date: Mon, 01 Aug 2016 22:19:35 +0200	[thread overview]
Message-ID: <16722.1470082775@hydra.kiddle.eu> (raw)
In-Reply-To: <20160731110516.GA20521@pileus.org>

Andy Spencer wrote:
> These are mostly static options with the exception of the frequency-set
> arguments for the governor and min/max frequencies, which are pulled
> from the output of frequency-info.

Thanks for contributing this. I've taken a look and have a few comments.
Mostly all minor points.

> +#compdef cpupower
> +
> +local -a ret state cmds args expl context line

ret should be initialised to 1 and shouldn't be of array type.

In this function, I'd recommand having _arguments update $curcontext
instead of using the context array. So pass -C to _arguments and use:
  local curcontext="$curcontext"

The array form with $context is only necessary if more than one state
is simultaneously possible. That happens when you have optional
arguments which cpupower doesn't.

> +
> +_arguments \
> +  '(-h --help)'{-h,--help}'[print usage information]' \
> +  '(-v --version)'{-v,--version}'[print package name and version]' \

As is often the case with version and help options, no other options are
valid following them. So these two exclusion lists can be reduced to
(- :)
e.g:
  '(- :)'{-h,--help}'[print usage information]'

Also, doesn't cpupower also have a -c/--cpu option for selecting
specific CPUs and -d/--debug?

> +  ':cmd:->cmds' \
> +  '*::arg:->args' && ret=0
> +
> +case $state in
> +  cmds)

It'd also be useful to complete these commands after the help command
but this doesn't do that.

> +  args)
> +    args=( )
> +    case ${words[1]} in

With commands that take subcommands, it is common practice to insert the
subcommand in to the command component of $curcontext at this point.
Something like:
  curcontext="${curcontext%:*}-$words[1]:"

> +      frequency-info)
> +        args+=(
> +          '(-e --debug)'{-e,--debug}'[print debug info]'
> +          '(-f --freq)'{-f,--freq}'[show current frequency]'
> +          '(-w --hwfreq)'{-w,--hwfreq}'[show current hardware frequency]'
> +          '(-l --hwlimits)'{-l,--hwlimits}'[show min/max frequency allowed]'
> +          '(-d --driver)'{-d,--driver}'[show the kernel driver in use]'
> +          '(-p --policy)'{-p,--policy}'[show the current cpufreq policy]'
> +          '(-g --governors)'{-g,--governors}'[show available governers]'
> +          '(-r --related-cpus)'{-a,--related-cpus}'[show cpus that run at the same frequency]'
> +          '(-a --affected-cpus)'{-a,--affected-cpus}'[show software controlled cpus]'
> +          '(-s --stats)'{-s,--stats}'[show cpufreq statistics]'
> +          '(-y --latency)'{-y,--latency}'[show frequency change latency]'
> +          '(-o --proc)'{-o,--proc}'[print old style proc info]'
> +          '(-m --human)'{-m,--human}'[use human readable output]'
> +          '(-n --no-rounding)'{-n,--no-rounding}'[disable rounding of values]'
> +        )

The exclusion lists could be a lot more restrictive. Most combinations
print:
  You can't specify more than one --cpu parameter and/or
  more than one output-specific argument
I think it is perhaps only the last three options that can be used with others.

> +      frequency-set)

> +          '(-f --freq)'{-f,--freq}'[new frequency for userspace governor]:freq->freq'

There's a colon missing on that line.


> +        args+=(
> +          '(-d --disable)'{-d,--disable}'[disable specific sleep state]:stateno'
> +          '(-e --enable)'{-e,--enable}'[enable specific sleep state]:stateno'

Not especially important but it's not possible to complete those
states is it? Documentation points to
/sys/devices/system/cpu/cpu*/cpuidle/state*. Those don't exist on
my system but that might be because it's very old.

> +      monitor)

> +          '-i[mesurement interval]:secs'

measurement

> +    _arguments "${args[@]}" && ret=0

You can pass -s to this _arguments as it seems cpupower lets you clump
together options, e.g. cpupower frequency-info -fn

> +    case $state in
> +      freq)
> +	compadd $(cpupower frequency-info |
> +		sed -n 's/ //g; s/,/ /g; s/availablefrequencysteps://p')

It'd be nice to have descriptions for this and the governors. e.g.:
  _wanted frequencies expl frequency compadd ....
And if you stick to the context array and no -C option to _arguments,
this would need to be:
   _wanted -C "$context" frequencies ...

Oliver


  parent reply	other threads:[~2016-08-01 20:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-31 11:05 Andy Spencer
2016-08-01  9:46 ` [PATCH] _cpupower: Move to correct subfolder Andy Spencer
2016-08-01 20:19 ` Oliver Kiddle [this message]
2016-08-01 21:41   ` [PATCH] Add completion for cpupower command Daniel Shahaf
2016-09-21 20:10   ` Oliver Kiddle
2016-08-08 19:31 ` Christian Heinrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16722.1470082775@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=andy@pileus.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).