github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/cmd/import.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 var importCmd = &cobra.Command{ 25 Use: "import URI", 26 Short: "Imports Oya pack in Oyafile", 27 Args: cobra.ExactArgs(1), 28 RunE: func(cmd *cobra.Command, args []string) error { 29 cwd, err := os.Getwd() 30 if err != nil { 31 return err 32 } 33 alias, err := cmd.Flags().GetString("alias") 34 if err != nil { 35 return err 36 } 37 return internal.Import(cwd, args[0], alias, cmd.OutOrStdout(), cmd.OutOrStderr()) 38 }, 39 } 40 41 func init() { 42 rootCmd.AddCommand(importCmd) 43 importCmd.Flags().StringP("alias", "a", "", "Import pack under alias name") 44 }