Skip to content

Commit

Permalink
chore: unexport cmd functions besides NewZarfCommand (#3421)
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 authored Jan 22, 2025
1 parent ff76a30 commit 30b79f4
Show file tree
Hide file tree
Showing 41 changed files with 536 additions and 643 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ issues:
- EXC0014
- EXC0015
exclude-dirs:
- "src/cmd/tools/helm" # Exclude linting code copied from Helm.
- "src/cmd/helm" # Exclude linting code copied from Helm.
- "src/internal/packager"
- "src/pkg/packager" # TODO(mkcp): Delete packager rules once refactor is complete
- "src/internal/packager2" # TODO(mkcp): Delete packager rules once refactor is complete
6 changes: 3 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ builds:
- -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor={{.Env.K8S_MODULES_MINOR_VER}}
- -X github.com/derailed/k9s/cmd.version={{.Env.K9S_VERSION}}
- -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Env.CRANE_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd/tools.syftVersion={{.Env.SYFT_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd/tools.archiverVersion={{.Env.ARCHIVER_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd/tools.helmVersion={{.Env.HELM_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd.syftVersion={{.Env.SYFT_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd.archiverVersion={{.Env.ARCHIVER_VERSION}}
- -X github.com/zarf-dev/zarf/src/cmd.helmVersion={{.Env.HELM_VERSION}}
goarch:
- amd64
- arm64
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ BUILD_ARGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$(K8S_MODULES_MIN
BUILD_ARGS += -X k8s.io/component-base/version.gitVersion=v$(K8S_MODULES_MAJOR_VER).$(K8S_MODULES_MINOR_VER).$(K8S_MODULES_PATCH_VER)
BUILD_ARGS += -X github.com/derailed/k9s/cmd.version=$(K9S_VERSION)
BUILD_ARGS += -X github.com/google/go-containerregistry/cmd/crane/cmd.Version=$(CRANE_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd/tools.syftVersion=$(SYFT_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd/tools.archiverVersion=$(ARCHIVER_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd/tools.helmVersion=$(HELM_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd.syftVersion=$(SYFT_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd.archiverVersion=$(ARCHIVER_VERSION)
BUILD_ARGS += -X github.com/zarf-dev/zarf/src/cmd.helmVersion=$(HELM_VERSION)

GIT_SHA := $(if $(shell git rev-parse HEAD),$(shell git rev-parse HEAD),"")
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
Expand Down
1 change: 1 addition & 0 deletions site/src/content/docs/commands/zarf.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ zarf COMMAND [flags]
* [zarf dev](/commands/zarf_dev/) - Commands useful for developing packages
* [zarf init](/commands/zarf_init/) - Prepares a k8s cluster for the deployment of Zarf packages
* [zarf package](/commands/zarf_package/) - Zarf package commands for creating, deploying, and inspecting packages
* [zarf say](/commands/zarf_say/) - Print Zarf logo
* [zarf tools](/commands/zarf_tools/) - Collection of additional tools to make airgap easier
* [zarf version](/commands/zarf_version/) - Shows the version of the running Zarf binary

45 changes: 45 additions & 0 deletions site/src/content/docs/commands/zarf_say.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: zarf say
description: Zarf CLI command reference for <code>zarf say</code>.
tableOfContents: false
---

<!-- Page generated by Zarf; DO NOT EDIT -->

## zarf say

Print Zarf logo

### Synopsis

Print out the adorable Zarf logo

```
zarf say [flags]
```

### Options

```
-h, --help help for say
```

### Options inherited from parent commands

```
-a, --architecture string Architecture for OCI images and Zarf packages
--insecure-skip-tls-verify Skip checking server's certificate for validity. This flag should only be used if you have a specific reason and accept the reduced security posture.
--log-format string [beta] Select a logging format. Defaults to 'console'. Valid options are: 'console', 'json', 'dev', 'legacy'. The legacy option will be removed in a coming release (default "console")
-l, --log-level string Log level when running Zarf. Valid options are: warn, info, debug, trace (default "info")
--no-color Disable colors in output
--no-log-file Disable log file creation
--no-progress Disable fancy UI progress bars, spinners, logos, etc
--plain-http Force the connections over HTTP instead of HTTPS. This flag should only be used if you have a specific reason and accept the reduced security posture.
--tmpdir string Specify the temporary directory to use for intermediate files
--zarf-cache string Specify the location of the Zarf cache directory (default "~/.zarf-cache")
```

### SEE ALSO

* [zarf](/commands/zarf/) - DevSecOps for Airgap

41 changes: 17 additions & 24 deletions src/cmd/tools/archiver.go → src/cmd/archiver.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package tools contains the CLI commands for Zarf.
package tools
// Package cmd contains the CLI commands for Zarf.
package cmd

import (
"fmt"
Expand All @@ -16,45 +16,41 @@ import (
"github.com/zarf-dev/zarf/src/pkg/layout"
)

// ldflags github.com/zarf-dev/zarf/src/cmd/tools.archiverVersion=x.x.x
// ldflags github.com/zarf-dev/zarf/src/cmd.archiverVersion=x.x.x
var archiverVersion string

// NewArchiverCommand creates the `tools archiver` sub-command and its nested children.
func NewArchiverCommand() *cobra.Command {
func newArchiverCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "archiver",
Aliases: []string{"a"},
Short: lang.CmdToolsArchiverShort,
Version: archiverVersion,
}

cmd.AddCommand(NewArchiverCompressCommand())
cmd.AddCommand(NewArchiverDecompressCommand())
cmd.AddCommand(newVersionCmd("mholt/archiver", archiverVersion))
cmd.AddCommand(newArchiverCompressCommand())
cmd.AddCommand(newArchiverDecompressCommand())
cmd.AddCommand(newToolsVersionCmd("mholt/archiver", archiverVersion))

return cmd
}

// ArchiverCompressOptions holds the command-line options for 'tools archiver compress' sub-command.
type ArchiverCompressOptions struct{}
type archiverCompressOptions struct{}

// NewArchiverCompressCommand creates the `tools archiver compress` sub-command.
func NewArchiverCompressCommand() *cobra.Command {
o := ArchiverCompressOptions{}
func newArchiverCompressCommand() *cobra.Command {
o := archiverCompressOptions{}

cmd := &cobra.Command{
Use: "compress SOURCES ARCHIVE",
Aliases: []string{"c"},
Short: lang.CmdToolsArchiverCompressShort,
Args: cobra.MinimumNArgs(2),
RunE: o.Run,
RunE: o.run,
}

return cmd
}

// Run performs the execution of 'tools archiver compress' sub-command.
func (o *ArchiverCompressOptions) Run(_ *cobra.Command, args []string) error {
func (o *archiverCompressOptions) run(_ *cobra.Command, args []string) error {
sourceFiles, destinationArchive := args[:len(args)-1], args[len(args)-1]
err := archiver.Archive(sourceFiles, destinationArchive)
if err != nil {
Expand All @@ -63,21 +59,19 @@ func (o *ArchiverCompressOptions) Run(_ *cobra.Command, args []string) error {
return err
}

// ArchiverDecompressOptions holds the command-line options for 'tools archiver decompress' sub-command.
type ArchiverDecompressOptions struct {
type archiverDecompressOptions struct {
unarchiveAll bool
}

// NewArchiverDecompressCommand creates the `tools archiver decompress` sub-command.
func NewArchiverDecompressCommand() *cobra.Command {
o := ArchiverDecompressOptions{}
func newArchiverDecompressCommand() *cobra.Command {
o := archiverDecompressOptions{}

cmd := &cobra.Command{
Use: "decompress ARCHIVE DESTINATION",
Aliases: []string{"d"},
Short: lang.CmdToolsArchiverDecompressShort,
Args: cobra.ExactArgs(2),
RunE: o.Run,
RunE: o.run,
}

cmd.Flags().BoolVar(&o.unarchiveAll, "decompress-all", false, "Decompress all tarballs in the archive")
Expand All @@ -88,8 +82,7 @@ func NewArchiverDecompressCommand() *cobra.Command {
return cmd
}

// Run performs the execution of 'tools archiver decompress' sub-command.
func (o *ArchiverDecompressOptions) Run(_ *cobra.Command, args []string) error {
func (o *archiverDecompressOptions) run(_ *cobra.Command, args []string) error {
sourceArchive, destinationPath := args[0], args[1]
err := archiver.Unarchive(sourceArchive, destinationPath)
if err != nil {
Expand Down
32 changes: 14 additions & 18 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package cmd contains the CLI commands for Zarf contains the CLI commands for Zarf.
// Package cmd contains the CLI commands for Zarf.
package cmd

import (
Expand All @@ -16,22 +16,20 @@ import (
"github.com/zarf-dev/zarf/src/pkg/utils/exec"
)

// ConnectOptions holds the command-line options for 'connect' sub-command.
type ConnectOptions struct {
type connectOptions struct {
cliOnly bool
zt cluster.TunnelInfo
}

// NewConnectCommand creates the `connect` sub-command and its nested children.
func NewConnectCommand() *cobra.Command {
o := &ConnectOptions{}
func newConnectCommand() *cobra.Command {
o := &connectOptions{}

cmd := &cobra.Command{
Use: "connect { REGISTRY | GIT | connect-name }",
Aliases: []string{"c"},
Short: lang.CmdConnectShort,
Long: lang.CmdConnectLong,
RunE: o.Run,
RunE: o.run,
}

cmd.Flags().StringVar(&o.zt.ResourceName, "name", "", lang.CmdConnectFlagName)
Expand All @@ -42,13 +40,12 @@ func NewConnectCommand() *cobra.Command {
cmd.Flags().BoolVar(&o.cliOnly, "cli-only", false, lang.CmdConnectFlagCliOnly)

// TODO(soltysh): consider splitting sub-commands into separate files
cmd.AddCommand(NewConnectListCommand())
cmd.AddCommand(newConnectListCommand())

return cmd
}

// Run performs the execution of 'connect' sub command.
func (o *ConnectOptions) Run(cmd *cobra.Command, args []string) error {
func (o *connectOptions) run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
l := logger.From(ctx)
target := ""
Expand Down Expand Up @@ -106,23 +103,22 @@ func (o *ConnectOptions) Run(cmd *cobra.Command, args []string) error {
}
}

// ConnectListOptions holds the command-line options for 'connect list' sub-command.
type ConnectListOptions struct{}
// connectListOptions holds the command-line options for 'connect list' sub-command.
type connectListOptions struct{}

// NewConnectListCommand creates the `connect list` sub-command.
func NewConnectListCommand() *cobra.Command {
o := &ConnectListOptions{}
// newConnectListCommand creates the `connect list` sub-command.
func newConnectListCommand() *cobra.Command {
o := &connectListOptions{}
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"l"},
Short: lang.CmdConnectListShort,
RunE: o.Run,
RunE: o.run,
}
return cmd
}

// Run performs the execution of 'connect list' sub-command.
func (o *ConnectListOptions) Run(cmd *cobra.Command, _ []string) error {
func (o *connectListOptions) run(cmd *cobra.Command, _ []string) error {
c, err := cluster.NewCluster()
if err != nil {
return err
Expand Down
Loading

0 comments on commit 30b79f4

Please sign in to comment.