Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add files for kando, a command line tool (#3158)
* Add kantools files * Review feedback * Rename ObjectStore command to Location. * Rename suffix to path
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kanisterio/kanister/pkg/kando" | ||
) | ||
|
||
func main() { | ||
kando.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kando | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
kanister "github.com/kanisterio/kanister/pkg" | ||
) | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
root := newRootCommand() | ||
if err := root.Execute(); err != nil { | ||
log.Errorf("%+v", err) | ||
} | ||
} | ||
|
||
func newRootCommand() *cobra.Command { | ||
// RootCmd represents the base command when called without any subcommands | ||
rootCmd := &cobra.Command{ | ||
Use: "kando <command>", | ||
Short: "A set of tools used from Kanister Blueprints", | ||
Version: kanister.VERSION, | ||
} | ||
rootCmd.AddCommand(newLocationCommand()) | ||
return rootCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package kando | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
const ( | ||
pathFlagName = "path" | ||
profileFlagName = "profile" | ||
) | ||
|
||
func newLocationCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "location <command>", | ||
Short: "Push and pull from object storage", | ||
} | ||
cmd.AddCommand(newLocationPushCommand()) | ||
cmd.AddCommand(newLocationPullCommand()) | ||
cmd.PersistentFlags().StringP(pathFlagName, "s", "", "Specify a path suffix (optional)") | ||
cmd.PersistentFlags().StringP(profileFlagName, "p", "", "Pass a Profile as a JSON string (required)") | ||
cmd.MarkFlagRequired(profileFlagName) | ||
return cmd | ||
} | ||
|
||
func pathFlag(cmd *cobra.Command) string { | ||
return cmd.Flag(pathFlagName).Value.String() | ||
} | ||
|
||
func unmarshalProfileFlag(cmd *cobra.Command) (*param.Profile, error) { | ||
profileJSON := cmd.Flag(profileFlagName).Value.String() | ||
p := ¶m.Profile{} | ||
err := json.Unmarshal([]byte(profileJSON), p) | ||
return p, errors.Wrap(err, "failed to unmarshal profile") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package kando | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
func newLocationPullCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pull <target>", | ||
Short: "Pull from s3-compliant object storage to a file or stdout", | ||
Args: cobra.ExactArgs(1), | ||
// TODO: Example invocations | ||
RunE: func(c *cobra.Command, args []string) error { | ||
return runLocationPull(c, args) | ||
}, | ||
} | ||
return cmd | ||
|
||
} | ||
|
||
func runLocationPull(cmd *cobra.Command, args []string) error { | ||
source := args[0] | ||
p, err := unmarshalProfileFlag(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
s := pathFlag(cmd) | ||
ctx := context.Background() | ||
return locationPull(ctx, p, s, source) | ||
} | ||
|
||
// TODO: Implement this function | ||
func locationPull(ctx context.Context, p *param.Profile, path string, source string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package kando | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/kanisterio/kanister/pkg/param" | ||
) | ||
|
||
func newLocationPushCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "push <source>", | ||
Short: "Push a source file or stdin stream to s3-compliant object storage", | ||
Args: cobra.ExactArgs(1), | ||
// TODO: Example invocations | ||
RunE: func(c *cobra.Command, args []string) error { | ||
return runLocationPush(c, args) | ||
}, | ||
} | ||
return cmd | ||
|
||
} | ||
|
||
func runLocationPush(cmd *cobra.Command, args []string) error { | ||
source := args[0] | ||
p, err := unmarshalProfileFlag(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
s := pathFlag(cmd) | ||
ctx := context.Background() | ||
return locationPush(ctx, p, s, source) | ||
} | ||
|
||
// TODO: Implement this function | ||
func locationPush(ctx context.Context, p *param.Profile, path string, source string) error { | ||
return nil | ||
} |