Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ func (c *Client) New(ctx context.Context, cfg Function) (err error) {

// Create a new Function project locally using the settings provided on a
// Function object.
func (c *Client) Create(f Function) (err error) {
func (c *Client) Create(cfg Function) (err error) {
// Create project root directory, if it doesn't already exist
if err = os.MkdirAll(f.Root, 0755); err != nil {
if err = os.MkdirAll(cfg.Root, 0755); err != nil {
return
}

Expand All @@ -442,11 +442,11 @@ func (c *Client) Create(f Function) (err error) {
// immediately exit with error (prior to actual creation) if this is
// a Function already initialized at that path (Create should never
// clobber a pre-existing Function)
defaults, err := NewFunction(f.Root)
f, err := NewFunctionFromDefaults(cfg)
if err != nil {
return
}
if defaults.Initialized() {
if f.Initialized() {
err = fmt.Errorf("Function at '%v' already initialized", f.Root)
return
}
Expand All @@ -463,16 +463,6 @@ func (c *Client) Create(f Function) (err error) {
return
}

// Assert runtime was provided, or default.
if f.Runtime == "" {
f.Runtime = DefaultRuntime
}

// Assert template name was provided, or default.
if f.Template == "" {
f.Template = DefaultTemplate
}

// Write out the template for a Function
// returns a Function which may be mutated based on the content of
// the template (default Function, builders, buildpacks, etc).
Expand All @@ -483,7 +473,7 @@ func (c *Client) Create(f Function) (err error) {

// Mark it as having been created via this client library and Write (save)
f.Created = time.Now()
if err = writeConfig(f); err != nil {
if err = f.Write(); err != nil {
return
}

Expand Down Expand Up @@ -544,9 +534,9 @@ func (c *Client) Build(ctx context.Context, path string) (err error) {
return
}

// Write out config, which will now contain a populated image tag
// if it had not already
if err = writeConfig(f); err != nil {
// Write (save) - Serialize the Function to disk
// Will now contain populated image tag.
if err = f.Write(); err != nil {
return
}

Expand Down Expand Up @@ -585,9 +575,9 @@ func (c *Client) Deploy(ctx context.Context, path string) (err error) {
return
}

// Store the produced image Digest in the config
// Record the Image Digest pushed.
f.ImageDigest = imageDigest
if err = writeConfig(f); err != nil {
if err = f.Write(); err != nil {
return
}

Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestNew(t *testing.T) {
root := "testdata/example.com/testNew"
defer Using(t, root)()

client := fn.New(fn.WithRegistry(TestRegistry))
client := fn.New(fn.WithRegistry(TestRegistry), fn.WithVerbose(true))

if err := client.New(context.Background(), fn.Function{Root: root}); err != nil {
t.Fatal(err)
Expand All @@ -58,13 +58,13 @@ func TestWritesTemplate(t *testing.T) {
}

// Assert the standard config file was written
if _, err := os.Stat(filepath.Join(root, fn.ConfigFile)); os.IsNotExist(err) {
t.Fatalf("Initialize did not result in '%v' being written to '%v'", fn.ConfigFile, root)
if _, err := os.Stat(filepath.Join(root, fn.FunctionFile)); os.IsNotExist(err) {
t.Fatalf("Initialize did not result in '%v' being written to '%v'", fn.FunctionFile, root)
}

// Assert a file from the template was written
if _, err := os.Stat(filepath.Join(root, "README.md")); os.IsNotExist(err) {
t.Fatalf("Initialize did not result in '%v' being written to '%v'", fn.ConfigFile, root)
t.Fatalf("Initialize did not result in '%v' being written to '%v'", fn.FunctionFile, root)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func runBuild(cmd *cobra.Command, _ []string, clientFn buildClientFn) (err error
}

// All set, let's write changes in the config to the disk
err = function.WriteConfig()
err = function.Write()
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s standardLoaderSaver) Load(path string) (fn.Function, error) {
}

func (s standardLoaderSaver) Save(f fn.Function) error {
return f.WriteConfig()
return f.Write()
}

var defaultLoaderSaver standardLoaderSaver
Expand Down
4 changes: 2 additions & 2 deletions cmd/config_envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func runAddEnvsPrompt(ctx context.Context, f fn.Function) (err error) {
f.Envs[insertToIndex] = newEnv
}

err = f.WriteConfig()
err = f.Write()
if err == nil {
fmt.Println("Environment variable entry was added to the function configuration")
}
Expand Down Expand Up @@ -419,7 +419,7 @@ func runRemoveEnvsPrompt(f fn.Function) (err error) {

if removed {
f.Envs = newEnvs
err = f.WriteConfig()
err = f.Write()
if err == nil {
fmt.Println("Environment variable entry was removed from the function configuration")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/config_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func runAddVolumesPrompt(ctx context.Context, f fn.Function) (err error) {

f.Volumes = append(f.Volumes, newVolume)

err = f.WriteConfig()
err = f.Write()
if err == nil {
fmt.Println("Volume entry was added to the function configuration")
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func runRemoveVolumesPrompt(f fn.Function) (err error) {

if removed {
f.Volumes = newVolumes
err = f.WriteConfig()
err = f.Write()
if err == nil {
fmt.Println("Volume entry was removed from the function configuration")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func runDeploy(cmd *cobra.Command, _ []string, clientFn deployClientFn) (err err
}

// All set, let's write changes in the config to the disk
err = function.WriteConfig()
err = function.Write()
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runRun(cmd *cobra.Command, args []string, clientFn runClientFn) (err error)
return
}

err = function.WriteConfig()
err = function.Write()
if err != nil {
return
}
Expand Down
Loading