func TestApp_RunAsSubcommandParseFlags(t *testing.T) { var context *cli.Context a := cli.NewApp() a.Commands = []cli.Command{ { Name: "foo", Action: func(c *cli.Context) { context = c }, Flags: []cli.Flag{ cli.StringFlag{ Name: "lang", Value: "english", Usage: "language for the greeting", }, }, Before: func(_ *cli.Context) error { return nil }, }, } a.Run([]string{"", "foo", "--lang", "spanish", "abcd"}) expect(t, context.Args().Get(0), "abcd") expect(t, context.String("lang"), "spanish") }
func CmdCurrent(c *cli.Context) { client, err := storage.List(c.String("region"), c.String("bucket"), c.String("path")) if err != nil { fmt.Println("Unable to complete request") } for _, element := range client.Contents { fmt.Println(*element.Key) } }
func CmdUpload(c *cli.Context) { fileList := getFiles(c.String("directory")) for _, f := range fileList { file, err := os.Open(f) if err != nil { fmt.Println(err) os.Exit(1) } defer file.Close() fileInfo, _ := file.Stat() var size int64 = fileInfo.Size() buffer := make([]byte, size) file.Read(buffer) fileBytes := bytes.NewReader(buffer) fileName := strings.Replace(file.Name(), c.String("directory"), "", -1) fileType := mime.TypeByExtension(path.Ext(f)) path := fmt.Sprintf("/%s/%s", c.String("path"), fileName) _, putErr := storage.Put(c.String("region"), c.String("bucket"), path, fileType, fileBytes, size) if putErr != nil { fmt.Println("%s", putErr) return } fmt.Println("Uploading file:" + file.Name()) } fmt.Println(fmt.Sprintf("Upload of directory %s complete", c.String("directory"))) }