[NEW] selfupdate
This commit is contained in:
21
cmd/list.go
21
cmd/list.go
@@ -15,14 +15,10 @@ import (
|
||||
|
||||
// listCmd represents the list command
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Use: "list <bucket>",
|
||||
Short: "List bucket contents",
|
||||
Long: `This command lists the content of specified bucket`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
isps3 := util.S3{
|
||||
Endpoint: "isp-dev.paasdev.sk:9000",
|
||||
@@ -36,7 +32,14 @@ to quickly create a Cobra application.`,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
objectCh := isps3.Client.ListObjects(ctx, "test", minio.ListObjectsOptions{
|
||||
found, err := isps3.Client.BucketExists(ctx, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("bucket %q does not exist", args[0])
|
||||
}
|
||||
objectCh := isps3.Client.ListObjects(ctx, args[0], minio.ListObjectsOptions{
|
||||
Prefix: "",
|
||||
Recursive: true,
|
||||
})
|
||||
|
@@ -22,7 +22,8 @@ to quickly create a Cobra application.`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
Version: "0.0.1",
|
||||
Version: "0.0.5",
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
|
86
cmd/selfupdate.go
Normal file
86
cmd/selfupdate.go
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"dummy/util"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/selfupdate"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
Ver string
|
||||
List bool
|
||||
)
|
||||
|
||||
// selfupdateCmd represents the selfupdate command
|
||||
var selfupdateCmd = &cobra.Command{
|
||||
Use: "selfupdate",
|
||||
Short: "Updates to latest or specific version",
|
||||
Long: `Updates to latest or specific version of dummy.
|
||||
|
||||
To update to latest version use:
|
||||
dummy selfupdate
|
||||
|
||||
To update to version 0.0.3 use:
|
||||
dummy selfupdate --version=0.0.3`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// Initialize minio client
|
||||
isps3 := util.S3{
|
||||
Endpoint: "isp-dev.paasdev.sk:9000",
|
||||
AccessKeyID: "LHHV6WR7EEMRS1RLX6BW",
|
||||
SecretAccessKey: "m8PvnzpRB4ORYwcJtzeJpboFUIBAfbZ3wwh3Bkcp",
|
||||
UseSSL: true,
|
||||
}
|
||||
err := isps3.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if List {
|
||||
updateCol := isps3.Client.ListObjects(context.Background(), "dummy", minio.ListObjectsOptions{
|
||||
Prefix: fmt.Sprintf("%s/dummy", runtime.GOOS),
|
||||
})
|
||||
|
||||
fmt.Println("Available updates:")
|
||||
for object := range updateCol {
|
||||
if object.Err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(object.Key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/dummy-%s", runtime.GOOS, Ver)
|
||||
fmt.Println("Updating dummy to: ", path)
|
||||
// Read the update
|
||||
update, err := isps3.Client.GetObject(context.Background(), "dummy", path, minio.GetObjectOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Do update
|
||||
err = selfupdate.Apply(update, selfupdate.Options{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Update finished")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(selfupdateCmd)
|
||||
|
||||
selfupdateCmd.Flags().StringVar(&Ver, "version", "latest", "Version to install (optional)")
|
||||
selfupdateCmd.Flags().BoolVar(&List, "list", false, "List available versions (optional)")
|
||||
|
||||
selfupdateCmd.MarkFlagsMutuallyExclusive("version", "list")
|
||||
}
|
Reference in New Issue
Block a user