zpwr: Implement zsh and bash autocompletion

Add generation of shell autocompletion scripts.

Acked-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Szabina Korbai <szkorbai@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Szabina Korbai
2026-03-06 15:13:41 +01:00
committed by Jan Höppner
parent 68309ccb7f
commit 31d576a595
5 changed files with 67 additions and 28 deletions

2
.gitignore vendored
View File

@@ -171,3 +171,5 @@ zpcictl/zpcictl
zpcictl/_zpcictl
zpcictl/zpcictl.bash
zpwr/zpwr
zpwr/_zpwr
zpwr/zpwr.bash

View File

@@ -7,6 +7,11 @@
include ../common.mak
zsh-completions = _zpwr
bash-completions = zpwr.bash
include ../common_autocomp.mak
all: zpwr
OBJECTS = zpwr.o

View File

@@ -0,0 +1,16 @@
/*
* SPDX-License-Identifier: MIT
*
* Copyright IBM Corp.
*/
#include "lib/util_autocomp.h"
#include "zpwr_cli.h"
int main(void)
{
generate_autocomp(opt_vec, "zpwr");
return 0;
}

View File

@@ -29,14 +29,15 @@
#include "lib/util_fmt.h"
#include "lib/util_opt.h"
#include "lib/util_prg.h"
#include "zpwr.h"
#include "zpwr_cli.h"
#define DIAG "/dev/diag"
#define NANO 1000000000ULL
#define NUMUNIT 5
#define NAMELEN 8
#define COMPWIDTH 27
#define OPT_FORMAT 256
enum part_power {
CPU,
@@ -95,33 +96,6 @@ static const struct util_prg prg = {
}
};
static struct util_opt opt_vec[] = {
UTIL_OPT_SECTION("OPTIONS"),
{
.option = { "format", required_argument, NULL, OPT_FORMAT },
.argument = "FORMAT",
.flags = UTIL_OPT_FLAG_NOSHORT,
.desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")",
},
{
.option = { "delay", required_argument, NULL, 'd' },
.argument = "NUMBER",
.desc = "Power readings after delay (seconds)",
},
{
.option = { "count", required_argument, NULL, 'c' },
.argument = "NUMBER",
.desc = "Number of power readings",
},
{
.option = { "stream", no_argument, NULL, 's' },
.desc = "Power readings in stream mode",
},
UTIL_OPT_HELP,
UTIL_OPT_VERSION,
UTIL_OPT_END
};
static int get_max_column_width(struct zpwrinfo *pinfo)
{
u64 max = 0;

42
zpwr/zpwr_cli.h Normal file
View File

@@ -0,0 +1,42 @@
/*
* SPDX-License-Identifier: MIT
*
* Copyright IBM Corp.
*/
#ifndef ZPWR_CLI_H
#define ZPWR_CLI_H
#include "lib/util_fmt.h"
#include "lib/util_opt.h"
#define OPT_FORMAT 256
static struct util_opt opt_vec[] = {
UTIL_OPT_SECTION("OPTIONS"),
{
.option = { "format", required_argument, NULL, OPT_FORMAT },
.argument = "FORMAT",
.flags = UTIL_OPT_FLAG_NOSHORT,
.desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")",
},
{
.option = { "delay", required_argument, NULL, 'd' },
.argument = "NUMBER",
.desc = "Power readings after delay (seconds)",
},
{
.option = { "count", required_argument, NULL, 'c' },
.argument = "NUMBER",
.desc = "Number of power readings",
},
{
.option = { "stream", no_argument, NULL, 's' },
.desc = "Power readings in stream mode",
},
UTIL_OPT_HELP,
UTIL_OPT_VERSION,
UTIL_OPT_END
};
#endif