diff --git a/cmd/root.go b/cmd/root.go index 1987655..c50bddf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -19,8 +19,11 @@ func Execute() { } } +var All bool + func init() { showCmd.PersistentFlags().StringP("file", "f", "", "Specifies the path to the spin.toml file you wish to visualize") showCmd.PersistentFlags().StringP("env", "e", "", "Specifies the path to the \".env\" file containing your Spin variables") + showCmd.PersistentFlags().BoolVarP(&All, "all", "a", false, "Output information about all component. Only applies if no component name is specified.") rootCmd.AddCommand(showCmd) } diff --git a/cmd/show.go b/cmd/show.go index 9372529..8a5896b 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -20,7 +20,7 @@ var showCmd = &cobra.Command{ Long: `The "show" command reads a spin.toml file and prints a table of components to the terminal. You can optionally specify a component to display information for a specific component only. By default, the command looks for a "spin.toml" file in the current directory.`, - Args: cobra.MaximumNArgs(1), + Args: cobra.MaximumNArgs(2), RunE: func(cmd *cobra.Command, args []string) error { // The path to a "spin.toml" file path, err := cmd.Flags().GetString("file") @@ -59,6 +59,13 @@ By default, the command looks for a "spin.toml" file in the current directory.`, // This won't throw errors because we are not checking the validity of a "spin.toml" file fmt.Print(showAllComponents(tomlData, envVars)) + // Also print info about all components if --all flag is set + if All { + for name, _ := range tomlData.Component { + fmt.Print(showSpecificComponent(tomlData, envVars, name)) + } + } + } else { terminalOutput, err := showSpecificComponent(tomlData, envVars, args[0]) if err != nil {