added wwctl genconf used to generate completions

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2023-03-01 16:42:58 +01:00
parent 6b40112175
commit 3526c2bd5f
5 changed files with 86 additions and 17 deletions

View File

@@ -88,6 +88,11 @@ GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS))
GOLANGCI_LINT := $(TOOLS_BIN)/golangci-lint
GOLANGCI_LINT_VERSION := v1.50.0
# helper functions
godeps=$(shell go list -deps -f '{{if not .Standard}}{{ $$dep := . }}{{range .GoFiles}}{{$$dep.Dir}}/{{.}} {{end}}{{end}}' $(1) | sed "s%${PWD}/%%g")
WWCTL_DEPS:=$(call godeps,cmd/wwctl/main.go)
WWCLIENT_DEPS:=$(call godeps,cmd/wwclient/main.go)
# use GOPROXY for older git clients and speed up downloads
GOPROXY ?= https://proxy.golang.org
export GOPROXY
@@ -96,7 +101,7 @@ export GOPROXY
WW_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree
# Default target
all: config vendor wwctl wwclient bash_completion.d man_pages config_defaults print_defaults wwapid wwapic wwapird print_mnts
all: config vendor wwctl wwclient man_pages config_defaults print_defaults wwapid wwapic wwapird print_mnts
# Validate source and build all packages
build: lint test-it vet all
@@ -197,7 +202,7 @@ files: all
install -m 0644 include/firewalld/warewulf.xml $(DESTDIR)$(FIREWALLDDIR)
install -m 0644 include/systemd/warewulfd.service $(DESTDIR)$(SYSTEMDDIR)
install -m 0644 LICENSE.md $(DESTDIR)$(WWDOCDIR)
cp bash_completion.d/warewulf $(DESTDIR)$(BASHCOMPDIR)
./wwctl genconf completions > $(DESTDIR)$(BASHCOMPDIR)/wwctl
cp man_pages/*.1* $(DESTDIR)$(MANDIR)/man1/
cp man_pages/*.5* $(DESTDIR)$(MANDIR)/man5/
install -m 0644 staticfiles/README-ipxe.md $(DESTDIR)$(WWDATADIR)/ipxe
@@ -210,25 +215,18 @@ init:
cp -r tftpboot/* $(WWTFTPDIR)/ipxe/
restorecon -r $(WWTFTPDIR)
wwctl:
cd cmd/wwctl; GOOS=linux go build -mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../wwctl
wwctl: $(WWCTL_DEPS)
@echo Building "$@"
@cd cmd/wwctl; GOOS=linux go build -mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../wwctl
wwclient:
cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static \
wwclient: $(WWCLIENT_DEPS)
@echo Building "$@"
@ cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static \
-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=/etc/warewulf/warewulf.conf'" -o ../../wwclient
install_wwclient: wwclient
install -m 0755 wwclient $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/wwclient
bash_completion:
cd cmd/bash_completion && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../bash_completion
bash_completion.d: bash_completion
install -d -m 0755 bash_completion.d
./bash_completion bash_completion.d/warewulf
man_page:
cd cmd/man_page && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
@@ -297,8 +295,6 @@ contclean:
rm -f wwctl
rm -rf .dist
rm -f $(WAREWULF)-$(VERSION).tar.gz
rm -f bash_completion
rm -rf bash_completion.d
rm -f man_page
rm -rf man_pages
rm -f warewulf.spec

View File

@@ -0,0 +1,23 @@
package completions
import (
"os"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
myArg := "bash"
if len(args) == 1 {
myArg = args[0]
}
switch myArg {
case "zsh":
cmd.GenZshCompletion(os.Stdout)
case "fish":
cmd.GenFishCompletion(os.Stdout, true)
default:
cmd.GenBashCompletion(os.Stdout)
}
return nil
}

View File

@@ -0,0 +1,22 @@
package completions
import "github.com/spf13/cobra"
var (
baseCmd = &cobra.Command{
Use: "completions",
Short: "shell completion",
Long: "This command generates the bash completions if no argument is given.",
RunE: CobraRunE,
Args: cobra.MaximumNArgs(1),
Aliases: []string{"bash"},
}
Zsh bool
)
func init() {
}
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -0,0 +1,26 @@
package genconf
import (
"github.com/hpcng/warewulf/internal/app/wwctl/genconf/completions"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
Use: "genconfig",
Short: "Generate various configurations",
Long: "This command will allow you to generate different configurations like bash-completions.",
Args: cobra.ExactArgs(0),
Aliases: []string{"cnf"},
}
ListFull bool
)
func init() {
baseCmd.AddCommand(completions.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
return baseCmd
}

View File

@@ -3,6 +3,7 @@ package wwctl
import (
"github.com/hpcng/warewulf/internal/app/wwctl/configure"
"github.com/hpcng/warewulf/internal/app/wwctl/container"
"github.com/hpcng/warewulf/internal/app/wwctl/genconf"
"github.com/hpcng/warewulf/internal/app/wwctl/kernel"
"github.com/hpcng/warewulf/internal/app/wwctl/node"
"github.com/hpcng/warewulf/internal/app/wwctl/overlay"
@@ -52,6 +53,7 @@ func init() {
rootCmd.AddCommand(server.GetCommand())
rootCmd.AddCommand(version.GetCommand())
rootCmd.AddCommand(ssh.GetCommand())
rootCmd.AddCommand(genconf.GetCommand())
}
// GetRootCommand returns the root cobra.Command for the application.