Skip to content

Commit

Permalink
Fixes issue 59 by rolling back changes made in PR 55
Browse files Browse the repository at this point in the history
  • Loading branch information
vedala committed Apr 29, 2020
1 parent da4a2b6 commit feb0a6d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 122 deletions.
41 changes: 3 additions & 38 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ func runFetchWrapper(c *cli.Context) {

// Run the fetch program
func runFetch(c *cli.Context) error {
options, err := parseOptions(c)
if err != nil {
return err
}

options := parseOptions(c)
if err := validateOptions(options); err != nil {
return err
}
Expand Down Expand Up @@ -198,7 +194,7 @@ func runFetch(c *cli.Context) error {
return nil
}

func parseOptions(c *cli.Context) (FetchOptions, error) {
func parseOptions(c *cli.Context) FetchOptions {
localDownloadPath := c.Args().First()
sourcePaths := c.StringSlice(OPTION_SOURCE_PATH)
assetChecksums := c.StringSlice(OPTION_RELEASE_ASSET_CHECKSUM)
Expand All @@ -212,37 +208,6 @@ func parseOptions(c *cli.Context) (FetchOptions, error) {
localDownloadPath = c.Args().Get(1)
}

optionsList := []string{
OPTION_REPO,
OPTION_TAG,
OPTION_COMMIT,
OPTION_BRANCH,
OPTION_GITHUB_TOKEN,
OPTION_SOURCE_PATH,
OPTION_RELEASE_ASSET,
OPTION_RELEASE_ASSET_CHECKSUM,
OPTION_RELEASE_ASSET_CHECKSUM_ALGO,
OPTION_GITHUB_API_VERSION,
OPTION_WITH_PROGRESS,
}

for _, option := range optionsList {
switch option {
case OPTION_SOURCE_PATH, OPTION_RELEASE_ASSET_CHECKSUM:
if c.IsSet(option) {
for _, slice := range c.StringSlice(option) {
if slice == "" {
return FetchOptions{}, fmt.Errorf("You specified the --%s flag but did not provide any value.", option)
}
}
}
default:
if c.IsSet(option) && c.String(option) == "" {
return FetchOptions{}, fmt.Errorf("You specified the --%s flag but did not provide any value.", option)
}
}
}

for _, assetChecksum := range assetChecksums {
assetChecksumMap[assetChecksum] = true
}
Expand All @@ -260,7 +225,7 @@ func parseOptions(c *cli.Context) (FetchOptions, error) {
LocalDownloadPath: localDownloadPath,
GithubApiVersion: c.String(OPTION_GITHUB_API_VERSION),
WithProgress: c.IsSet(OPTION_WITH_PROGRESS),
}, nil
}
}

func validateOptions(options FetchOptions) error {
Expand Down
84 changes: 0 additions & 84 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"os"
"testing"

cli "gopkg.in/urfave/cli.v1"
)

// Expect to download 2 assets:
Expand Down Expand Up @@ -60,85 +58,3 @@ func TestInvalidReleaseAssetsRegex(t *testing.T) {
t.Fatalf("Expected error for invalid regex")
}
}

func TestEmptyOptionValues(t *testing.T) {
app := cli.NewApp()
app.Name = "main_test"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: OPTION_REPO,
},
cli.StringFlag{
Name: OPTION_COMMIT,
},
cli.StringFlag{
Name: OPTION_BRANCH,
},
cli.StringFlag{
Name: OPTION_TAG,
},
cli.StringFlag{
Name: OPTION_GITHUB_TOKEN,
EnvVar: ENV_VAR_GITHUB_TOKEN,
},
cli.StringSliceFlag{
Name: OPTION_SOURCE_PATH,
},
cli.StringFlag{
Name: OPTION_RELEASE_ASSET,
},
cli.StringSliceFlag{
Name: OPTION_RELEASE_ASSET_CHECKSUM,
},
cli.StringFlag{
Name: OPTION_RELEASE_ASSET_CHECKSUM_ALGO,
},
cli.StringFlag{
Name: OPTION_GITHUB_API_VERSION,
Value: "v3",
},
cli.StringFlag{
Name: OPTION_WITH_PROGRESS,
},
}

app.Action = func(c *cli.Context) error {
_, err := parseOptions(c)
return err
}

var args []string
var expected string
var err error

optionsList := []string{
OPTION_REPO,
OPTION_COMMIT,
OPTION_BRANCH,
OPTION_TAG,
OPTION_GITHUB_TOKEN,
OPTION_SOURCE_PATH,
OPTION_RELEASE_ASSET,
OPTION_RELEASE_ASSET_CHECKSUM,
OPTION_RELEASE_ASSET_CHECKSUM_ALGO,
OPTION_GITHUB_API_VERSION,
OPTION_WITH_PROGRESS,
}

for _, option := range optionsList {
args = os.Args[0:1]
dashedOption := "--" + option
emptyOption := dashedOption + "="
args = append(args, emptyOption)

err = app.Run(args)
expected = fmt.Sprintf("You specified the %s flag but did not provide any value.", dashedOption)
if (err != nil) && (err.Error() != expected) {
t.Fatalf("Expected '%s' but received '%s'", expected, err.Error())
}

if err == nil {
t.Fatalf("Expected '%s' but received nothing", expected)
}
}
}

0 comments on commit feb0a6d

Please sign in to comment.