airshipctl/cmd/config/get_manifest.go
Ruslan Aliev 864184f053 Refactor config get-manifest command
This commit addresses the bug that user is unable to see retrieved
manifest name or names, also simplifies the internal logic and
reorganizes unit tests.

Change-Id: I89bac0af811f744c209be2aee921033a5e8a4fca
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
Closes: #505
2021-04-03 22:27:43 -05:00

69 lines
1.9 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/config"
)
const (
getManifestsLong = `
Display a specific manifest information, or all defined manifests if no name is provided.
`
getManifestsExample = `
# List all the manifests airshipctl knows about
airshipctl config get-manifests
# Display a specific manifest
airshipctl config get-manifest e2e
`
)
// NewGetManifestCommand creates a command for viewing the manifest information
// defined in the airshipctl config file.
func NewGetManifestCommand(cfgFactory config.Factory) *cobra.Command {
var manifestName string
cmd := &cobra.Command{
Use: "get-manifest NAME",
Short: "Get a manifest(s) information from the airshipctl config",
Long: getManifestsLong[1:],
Example: getManifestsExample,
Args: GetManifestNArgs(&manifestName),
Aliases: []string{"get-manifests"},
RunE: func(cmd *cobra.Command, args []string) error {
return config.RunGetManifest(cfgFactory, manifestName, cmd.OutOrStdout())
},
}
return cmd
}
// GetManifestNArgs is used to process arguments for get-manifest cmd
func GetManifestNArgs(manifestName *string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if cmd.CalledAs() == "get-manifests" {
return cobra.ExactArgs(0)(cmd, args)
}
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
*manifestName = args[0]
return nil
}
}