github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/sealer/cmd/inspect.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cmd
    16  
    17  import (
    18  	"fmt"
    19  
    20  	v1 "github.com/alibaba/sealer/types/api/v1"
    21  	"github.com/alibaba/sealer/utils/platform"
    22  
    23  	"github.com/spf13/cobra"
    24  
    25  	"github.com/alibaba/sealer/pkg/image"
    26  )
    27  
    28  var inspectPlatformFlag string
    29  
    30  // inspectCmd represents the inspect command
    31  var inspectCmd = &cobra.Command{
    32  	Use:   "inspect",
    33  	Short: "print the image information or clusterFile",
    34  	Long:  `sealer inspect ${image id} to print image information`,
    35  	Args:  cobra.ExactArgs(1),
    36  	RunE: func(cmd *cobra.Command, args []string) error {
    37  		var targetPlatforms []*v1.Platform
    38  		if inspectPlatformFlag != "" {
    39  			tp, err := platform.ParsePlatforms(inspectPlatformFlag)
    40  			if err != nil {
    41  				return err
    42  			}
    43  			targetPlatforms = tp
    44  		}
    45  		file, err := image.GetImageDetails(args[0], targetPlatforms)
    46  		if err != nil {
    47  			return fmt.Errorf("failed to find information by image %s: %v", args[0], err)
    48  		}
    49  		fmt.Println(file)
    50  		return nil
    51  	},
    52  }
    53  
    54  func init() {
    55  	rootCmd.AddCommand(inspectCmd)
    56  	inspectCmd.Flags().StringVar(&inspectPlatformFlag, "platform", "", "set cloud image platform")
    57  }