Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

allow passing whole directory as -f argument #166

Merged
merged 1 commit into from
Jul 27, 2017

Conversation

kadel
Copy link
Member

@kadel kadel commented Jul 18, 2017

if dir is provided, use all *.yml files in that directory

fixes #155

TODO:

  • finish unit tests
  • maybe call GetAllYMLFiles from ExecuteKubectl?

@kedge-bot
Copy link
Collaborator

@kadel, thank you for the pull request! We'll ping some people to review your PR. @containscafeine, please review this.

@kedge-bot kedge-bot requested a review from concaf July 18, 2017 15:17
@kedgeproject kedgeproject deleted a comment from kedge-bot Jul 18, 2017
@kadel kadel force-pushed the readFromDir branch 7 times, most recently from 93ca04d to 3e3e3f7 Compare July 20, 2017 13:00
@kadel kadel changed the title [WIP] allow passing whole directory as -f argument allow passing whole directory as -f argument Jul 20, 2017
@concaf
Copy link
Collaborator

concaf commented Jul 25, 2017

passing in a directory with no YAML files does not fail and exits silently, let's error out here? -

$ kedge generate -f examples/
$
$ echo $?
0

@kadel
Copy link
Member Author

kadel commented Jul 25, 2017

passing in a directory with no YAML files does not fail and exits silently, let's error out here? -

good catch @containscafeine

I've added error

▶ ./kedge generate -f empty                     
unable to get YAML files: no *.yml or *.yaml files were found

pkg/cmd/util.go Outdated

yamlFiles, err := filepath.Glob(filepath.Join(path, "*.yaml"))
if err != nil {
return nil, errors.Wrapf(err, "can't list *.yml files in %s", path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spell: s/ yml / yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@surajssd
Copy link
Member

@kadel apart from that spell mistake rest LGTM!

pkg/cmd/util.go Outdated

// GetAllYMLFiles if path in argument is directory get all *.yml and *.yaml files
// in that directory. If path is file just add it to output list as it is.
func GetAllYMLFiles(paths []string) ([]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to GetAllYAMLFiles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

pkg/cmd/util.go Outdated
@@ -56,3 +58,40 @@ func getApplicationsFromFiles(files []string) ([]inputData, error) {
}
return appData, nil
}

// GetAllYMLFiles if path in argument is directory get all *.yml and *.yaml files
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the string "GetAllYMLFiles" in the beginning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ;-)
Why would you want to remove it? In favor of what?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I mean why do we want the function name in the starting of the comment?

pkg/cmd/util.go Outdated
}
files = append(files, ymlFiles...)

yamlFiles, err := filepath.Glob(filepath.Join(path, "*.yaml"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are having to run filepath.Glob twice, once for yaml and one for yml. Can we use some pattern matching to make it one?
I tried ls *.y{a,}ml for the ls command, and it worked there, can we have something similar here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patern language for Glob is descibed in https://golang.org/pkg/path/filepath/#Match

Haven't found a way how to do it in one query :-(

pkg/cmd/util.go Outdated
}

}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove newline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it here ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is fine, but we are not following this style anywhere else in the code (or at least I could not find it) :( So to keep with the code style, does it make sense to keep it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it makes the code more readable, but whatever, I've removed the lines. I don't want to argue about empty lines.

pkg/cmd/util.go Outdated
if len(files) == 0 {
return nil, fmt.Errorf("no *.yml or *.yaml files were found")
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove newline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it here ;-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

func Generate(files []string) error {
func Generate(paths []string) error {

files, err := GetAllYAMLFiles(paths)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadel instead of changing functions here, and getting all YAML files here, I think it makes more sense to do this in cmd/{apply,create,delete,generate}.go, similar to the way if err := ifFilesPassed(InputFiles); err != nil { is being done in those files.
We can create one validateFiles function in cmd/util.go which calls ifFilesPassed and GetAllYAMLFiles since these are common in all of cmd/{apply,create,delete,generate}.go files, and just call validateFiles in all of them.

It will make this behavior more uniform instead of adding in func Generate used by only generate.go and func ExecuteKubectl used by {apply,create,delete}.go.

WDYT?

Copy link
Member Author

@kadel kadel Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was done like this in the first place, but then I changed that, to this.
It's closer to application logic and I think that in cmd/* should be mostly the code that handles argument parsing and validation.
It's also better to have it inside ExecuteKubectl and in Generate as it can't happen that someone will forget to call when using Generate/ExecuteKubectl

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadel hmm, makes sense to move both ifFilesPassed and GetAllYAMLFiles out of cmd, but that's for another PR. Tracking in #185

if dir is provided, use all *.yml and *.yaml files in that directory
Copy link
Collaborator

@concaf concaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @kadel, this is a great UX push 🎉

@concaf concaf merged commit d2acf4d into kedgeproject:master Jul 27, 2017
@kadel kadel deleted the readFromDir branch July 27, 2017 07:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing whole directory as argument for -f
4 participants