Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Mar 22, 2019
1 parent 7d181a2 commit 5f9f1e2
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"github.com/spf13/cobra"
)

var (
buildOutput string
)

// NewCmdDeploy describes the CLI command to deploy artifacts.
func NewCmdDeploy(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -37,5 +41,6 @@ func NewCmdDeploy(out io.Writer) *cobra.Command {
AddRunDevFlags(cmd)
AddRunDeployFlags(cmd)
cmd.Flags().StringSliceVar(&opts.PreBuiltImages, "images", nil, "A list of pre-built images to deploy")
cmd.Flags().StringVar(&buildOutput, "build-output", "", "A list of pre-built images to deploy")
return cmd
}
110 changes: 110 additions & 0 deletions cmd/skaffold/app/flags/filepath.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package flags

import (
"fmt"
"os"
)

// InputFilepath represents a input file command line argument
// InputFilepath type makes sure the file exists.
type InputFilepath filepathFlag

// OutputFilepath represents a output file command line argument.
// OutputFilepath make sure the path can be written to.
type OutputFilepath filepathFlag

func NewInputFilepathFlag(value string) *InputFilepath {
return &InputFilepath{
path: value,
shouldExist: true,
}
}

func (f *InputFilepath) Usage() string {
return "Path to a input file."
}

func (f *InputFilepath) Type() string {
return fmt.Sprintf("%T", f)
}

func (f *InputFilepath) Set(value string) error {
return nil
}

func (f *InputFilepath) String() string {
return f.path
}

func NewOutputFilepathFlag(value string) *OutputFilepath {
return &OutputFilepath{
path: value,
canWrite: true,
}
}

func (f *OutputFilepath) Type() string {
return fmt.Sprintf("%T", f)
}

func (f *OutputFilepath) Usage() string {
return "Path to an output filepath."
}

func (f *OutputFilepath) Set(value string) error {
return nil
}

func (f *OutputFilepath) String() string {
return f.path
}

type filepathFlag struct {
path string
shouldExist bool
canWrite bool
}

func (f *filepathFlag) Set(value string) error {
//if
return nil
}

func newFilepathFlag(value string, exists bool, canWrite bool) *filepathFlag {
return &filepathFlag{
path: value,
shouldExist: exists,
canWrite: canWrite,
}
}

func (f filepathFlag) isValid() error {
if f.shouldExist {
if _, err := os.Stat(f.path); os.IsNotExist(err) {
return err
}
} else if f.canWrite {
_, err := os.Create(f.path)
defer os.Remove(f.path)
if err != nil {
return err
}
}
return nil
}
51 changes: 51 additions & 0 deletions cmd/skaffold/app/flags/filepath_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package flags

import (
"testing"
)

func TestNewInputFile(t *testing.T) {

flag := NewInputFilepath("test.out")
}

func TestInputFileFlagSet(t *testing.T) {
flag := NewInputFilepath("test.out")
if err := flag.Set(rawTemplate); err != nil {
t.Errorf("Error setting flag value: %s", err)
}

if err := flag.Set("{{start}} bad template"); err == nil {
t.Errorf("Expected error setting flag but got none.")
}
}

func TestTemplateString(t *testing.T) {
flag := NewTemplateFlag(rawTemplate, nil)
if rawTemplate != flag.String() {
t.Errorf("Flag String() does not match. Expected %s, Actual %s", rawTemplate, flag.String())
}
}

func TestTemplateType(t *testing.T) {
flag := &TemplateFlag{}
if flag.Type() != expectedFlagType {
t.Errorf("Flag returned wrong type. Expected %s, Actual %s", expectedFlagType, flag.Type())
}
}

0 comments on commit 5f9f1e2

Please sign in to comment.