forked from GoogleContainerTools/skaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two new flags, Inputfilepath, Outputfilepath
1. Inputfilepath: Inputfilepath flag, makes sure the file present exists. 2. Outputfilepath: Outputfilepath flag does not do any validation right now. Motivation: For, GoogleContainerTools#922 I am going to add `--build-output` as new flag to `skaffold build` to dump all artifacts built with with their tags. Similarly, the deploy will have additional flag `--build-artifacts` which will point to the output written by `skaffold build --build-output <file>` The Inputfilepath, can also be used to replace all the places where we expect an input file without repeating validation. ``` (add_flag_to_deploy)$ git grep 'Filename or URL to the pipeline' cmd/skaffold/app/cmd/cmd.go: cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file") cmd/skaffold/app/cmd/diagnose.go: cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file") cmd/skaffold/app/cmd/fix.go: cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file") cmd/skaffold/app/cmd/init.go: cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file") ```
- Loading branch information
Showing
6 changed files
with
225 additions
and
122 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
This file was deleted.
Oops, something went wrong.
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,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 ( | ||
"fmt" | ||
) | ||
|
||
// InputFilepath represents a input file command line argument | ||
// InputFilepath type makes sure the file exists. | ||
type InputFilepath struct { | ||
filepathFlag | ||
} | ||
|
||
func NewInputFilepath(value string) *InputFilepath { | ||
return &InputFilepath{ | ||
filepathFlag{ | ||
path: value, | ||
shouldExist: true, | ||
}} | ||
} | ||
|
||
func (f *InputFilepath) Usage() string { | ||
return "Path to an input file." | ||
} | ||
|
||
func (f *InputFilepath) Type() string { | ||
return fmt.Sprintf("%T", f) | ||
} | ||
|
||
func (f *InputFilepath) Set(value string) error { | ||
return f.SetIfValid(value) | ||
} | ||
|
||
func (f *InputFilepath) String() string { | ||
return f.path | ||
} |
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,72 @@ | ||
/* | ||
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" | ||
|
||
"github.com/GoogleContainerTools/skaffold/testutil" | ||
) | ||
|
||
func TestNewInputFile(t *testing.T) { | ||
flag := NewInputFilepath("test.in") | ||
expectedFlag := InputFilepath{filepathFlag{ | ||
path: "test.in", | ||
shouldExist: true, | ||
}} | ||
if *flag != expectedFlag { | ||
t.Errorf("expected %s, actual %s", &expectedFlag, flag) | ||
} | ||
} | ||
|
||
func TestInputFileFlagSet(t *testing.T) { | ||
dir, cleanUp := testutil.NewTempDir(t) | ||
defer cleanUp() | ||
filename := "exists.in" | ||
dir.Write(filename, "some input") | ||
|
||
var tests = []struct { | ||
description string | ||
filename string | ||
shouldErr bool | ||
}{ | ||
{ | ||
description: "should not error when file is present", | ||
filename: dir.Path(filename), | ||
}, | ||
{ | ||
description: "should error when file is present", | ||
filename: "does_not_exist.in", | ||
shouldErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
flag := NewInputFilepath("") | ||
err := flag.Set(test.filename) | ||
expectedFlag := NewInputFilepath(test.filename) | ||
testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, expectedFlag.String(), flag.String()) | ||
} | ||
} | ||
|
||
func TestInputFilepathType(t *testing.T) { | ||
flag := NewInputFilepath("test.in") | ||
expectedFlagType := "*flags.InputFilepath" | ||
if flag.Type() != expectedFlagType { | ||
t.Errorf("Flag returned wrong type. Expected %s, Actual %s", expectedFlagType, flag.Type()) | ||
} | ||
} |
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,49 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// OutputFilepath represents a output file command line argument. | ||
// OutputFilepath currently does not provide any validation. | ||
type OutputFilepath struct { | ||
filepathFlag | ||
} | ||
|
||
func NewOutputFilepath(value string) *OutputFilepath { | ||
return &OutputFilepath{filepathFlag{ | ||
path: value, | ||
}} | ||
} | ||
|
||
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 f.SetIfValid(value) | ||
} | ||
|
||
func (f *OutputFilepath) String() string { | ||
return f.path | ||
} |
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,38 @@ | ||
/* | ||
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 TestNewOutputFilepathType(t *testing.T) { | ||
flag := NewOutputFilepath("test.out") | ||
expectedFlag := OutputFilepath{filepathFlag{ | ||
path: "test.out", | ||
}} | ||
if *flag != expectedFlag { | ||
t.Errorf("expected %s, actual %s", &expectedFlag, flag) | ||
} | ||
} | ||
|
||
func TestOutputFileFlagSet(t *testing.T) { | ||
flag := NewOutputFilepath("") | ||
if err := flag.Set("test.out"); err != nil { | ||
t.Errorf("Error setting flag value: %s", err) | ||
} | ||
} |