feat: updated implementations for cmds
This commit is contained in:
parent
7a96bfd6c7
commit
59a5225b28
7 changed files with 331 additions and 102 deletions
28
cmd/list.go
28
cmd/list.go
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.towk2.me/towk/configurator/pkg/client"
|
||||
"git.towk2.me/towk/makeshift/pkg/client"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -14,19 +14,24 @@ import (
|
|||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Example: `
|
||||
# list files in a remote data directory
|
||||
configurator list --path test
|
||||
configurator list --host https://example.com --path test
|
||||
curl https://example.com/list/test
|
||||
# list files in a remote data directory
|
||||
configurator list --path test
|
||||
configurator list --host http://localhost:5050 --path test
|
||||
|
||||
# list files using 'curl'
|
||||
curl http://localhost:5050/list/test
|
||||
`,
|
||||
Args: cobra.NoArgs,
|
||||
Short: "List all files in a remote data directory",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
setenv(&host, "CONFIGURATOR_HOST")
|
||||
setenv(&path, "CONFIGURATOR_PATH")
|
||||
setenv(cmd, "host", "MAKESHIFT_HOST")
|
||||
setenv(cmd, "path", "MAKESHIFT_PATH")
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
path, _ = cmd.Flags().GetString("path")
|
||||
|
||||
c = client.New(host)
|
||||
body []byte
|
||||
output []string
|
||||
|
|
@ -44,7 +49,10 @@ var listCmd = &cobra.Command{
|
|||
Method: http.MethodGet,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("url", host).Msg("failed to make request")
|
||||
log.Error().Err(err).
|
||||
Str("host", host).
|
||||
Str("path", path).
|
||||
Msg("failed to make request")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +68,8 @@ var listCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
listCmd.Flags().StringVar(&host, "host", "http://localhost:5050", "Set the configurator remote host (can be set with CONFIGURATOR_HOST)")
|
||||
listCmd.Flags().StringVarP(&path, "path", "p", ".", "Set the path to list files (can be set with CONFIGURATOR_PATH)")
|
||||
listCmd.Flags().String("host", "http://localhost:5050", "Set the configurator remote host (can be set with MAKESHIFT_HOST)")
|
||||
listCmd.Flags().StringP("path", "p", ".", "Set the path to list files (can be set with MAKESHIFT_PATH)")
|
||||
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue