allow path to be provided to commands

This commit is contained in:
Luke K 2020-05-11 01:41:27 +00:00
parent 853d0eb4db
commit 88d806b52b
No known key found for this signature in database
GPG Key ID: 4896F75BAF2E1966
6 changed files with 33 additions and 14 deletions

View File

@ -53,6 +53,7 @@ func create(cmd *cobra.Command, args []string) (err error) {
// Assemble parameters for use in client's 'create' invocation.
var (
language = args[0] // language is the first argument
path = "" // path is defaulted to current working directory.
local = viper.GetBool("local") // Only perform local creation steps
internal = viper.GetBool("internal") // Do not expose publicly (internal route only)
name = viper.GetString("name") // Explicit name override (by default path-derives)
@ -61,6 +62,11 @@ func create(cmd *cobra.Command, args []string) (err error) {
namespace = viper.GetString("namespace") // namespace at registry (user or org name)
)
// If path is provided
if len(args) == 2 {
path = args[1]
}
// Namespace can not be defaulted.
if namespace == "" {
return errors.New("image registry namespace (--namespace or FAAS_NAMESPACE is required)")
@ -100,5 +106,8 @@ func create(cmd *cobra.Command, args []string) (err error) {
// Invoke the creation of the new Service Function locally.
// Returns the final address.
return client.Create(language)
// Name can be empty string (path-dervation will be attempted)
// Path can be empty, defaulting to current working directory.
return client.Create(language, name, path)
}

View File

@ -10,8 +10,8 @@ import (
func init() {
root.AddCommand(deleteCmd)
createCmd.Flags().StringP("name", "n", "", "optionally specify an explicit name to remove, overriding path-derivation. $FAAS_NAME")
viper.BindPFlag("name", createCmd.Flags().Lookup("name"))
deleteCmd.Flags().StringP("name", "n", "", "optionally specify an explicit name to remove, overriding path-derivation. $FAAS_NAME")
viper.BindPFlag("name", deleteCmd.Flags().Lookup("name"))
}
var deleteCmd = &cobra.Command{

View File

@ -43,7 +43,7 @@ func describe(cmd *cobra.Command, args []string) (err error) {
}
describer.Verbose = verbose
client, err := faas.New(".",
client, err := faas.New(
faas.WithVerbose(verbose),
faas.WithDescriber(describer),
)

View File

@ -22,17 +22,15 @@ var listCmd = &cobra.Command{
}
func list(cmd *cobra.Command, args []string) (err error) {
var (
verbose = viper.GetBool("verbose")
)
verbose := viper.GetBool("verbose")
lister, err := knative.NewLister(client.DefaultNamespace)
lister, err := knative.NewLister(faas.DefaultNamespace)
if err != nil {
return
}
lister.Verbose = verbose
client, err := faas.New(".",
client, err := faas.New(
faas.WithVerbose(verbose),
faas.WithLister(lister),
)

View File

@ -21,17 +21,24 @@ var runCmd = &cobra.Command{
}
func run(cmd *cobra.Command, args []string) (err error) {
var verbose = viper.GetBool("verbose")
var (
path = "" // defaults to current working directory
verbose = viper.GetBool("verbose")
)
if len(args) == 1 {
path = args[0]
}
runner := appsody.NewRunner()
runner.Verbose = verbose
client, err := faas.New(".",
client, err := faas.New(
faas.WithRunner(runner),
faas.WithVerbose(verbose))
if err != nil {
return
}
return client.Run()
return client.Run(path)
}

View File

@ -26,11 +26,16 @@ var updateCmd = &cobra.Command{
func update(cmd *cobra.Command, args []string) (err error) {
var (
path = "" // defaults to current working directory
verbose = viper.GetBool("verbose") // Verbose logging
registry = viper.GetString("registry") // Registry (ex: docker.io)
namespace = viper.GetString("namespace") // namespace at registry (user or org name)
)
if len(args) == 1 {
path = args[0]
}
// Namespace can not be defaulted.
if namespace == "" {
return errors.New("image registry namespace (--namespace or FAAS_NAMESPACE is required)")
@ -48,7 +53,7 @@ func update(cmd *cobra.Command, args []string) (err error) {
updater := kn.NewUpdater()
updater.Verbose = verbose
client, err := faas.New(".",
client, err := faas.New(
faas.WithVerbose(verbose),
faas.WithBuilder(builder),
faas.WithPusher(pusher),
@ -58,5 +63,5 @@ func update(cmd *cobra.Command, args []string) (err error) {
return
}
return client.Update()
return client.Update(path)
}