github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/cmd/get.go (about)

     1  // Copyright © 2018 NAME HERE <EMAIL ADDRESS>
     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  	"os"
    19  
    20  	"github.com/spf13/cobra"
    21  	"github.com/tooploox/oya/cmd/internal"
    22  )
    23  
    24  // getCmd represents the get command
    25  var getCmd = &cobra.Command{
    26  	Use:   "get URI",
    27  	Short: "Get Oya pack from external repo",
    28  	Args:  cobra.ExactArgs(1),
    29  	RunE: func(cmd *cobra.Command, args []string) error {
    30  		cwd, err := os.Getwd()
    31  		if err != nil {
    32  			return err
    33  		}
    34  
    35  		update, err := cmd.Flags().GetBool("update")
    36  		if err != nil {
    37  			return err
    38  		}
    39  		return internal.Get(cwd, args[0], update, cmd.OutOrStdout(), cmd.OutOrStderr())
    40  	},
    41  }
    42  
    43  func init() {
    44  	rootCmd.AddCommand(getCmd)
    45  	getCmd.Flags().BoolP("update", "u", false,
    46  		"Update the package to the latest available version")
    47  	// NOTE: --update flag mentioned in one of the error messages
    48  }