Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to load variable from file #614

Closed
wants to merge 5 commits into from

Conversation

bradrydzewski
Copy link
Contributor

@bradrydzewski bradrydzewski commented Mar 31, 2017

This demonstrates a potential solution for #613. If there is interest in possibly adding this feature we can flush out the implementation

@bradrydzewski bradrydzewski changed the title [WIP] ability to load variable from file Ability to load variable from file Apr 1, 2017
@bradrydzewski
Copy link
Contributor Author

The failed unit test is because I updated the documentation in the readme without realizing there were validations. I wasn't exactly sure how to fix, but if someone can point me in the right direction I can update the pr

@tboerger
Copy link

tboerger commented Apr 1, 2017

Awesome, that looks great

@bradrydzewski
Copy link
Contributor Author

@jszwedko friendly ping, looks like you are the most active maintainer. I was wondering your thoughts, and if I could get a review. Thanks!

@jszwedko
Copy link
Contributor

jszwedko commented Apr 7, 2017

@bradrydzewski 👍 this is looking good, thanks for the contribution!

My only thought is that we may want to more explicitly document in the README what the order of precedence of the sources is (I was surprised we didn't already, but it feels prudent to do so now given the addition of the new source).

@@ -32,6 +32,7 @@ applications in an expressive way.
+ [Alternate Names](#alternate-names)
+ [Ordering](#ordering)
+ [Values from the Environment](#values-from-the-environment)
+ [Values from files](#values-from-files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the linter wants this to match the heading (capital "Files")

README.md Outdated

<!-- {
"args": ["&#45;&#45;help"],
"output": "language for the greeting.*APP_LANG"
Copy link
Contributor

Choose a reason for hiding this comment

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

gfmrun expects the output specified here to match the program output when ran (this helps make the examples are not invalidated by code changes). In this particular case, I might suggest writing a temporary file in the example and then having a default action on app that prints out the value, updating this expected output to match.

You can test locally via:

go get github.com/urfave/gfmrun/...
./runtests gfmrun

Copy link
Contributor

Choose a reason for hiding this comment

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

Also removing the --help from the args.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can find more details about gfmrun here: https://github.com/urfave/gfmrun#go

@jszwedko
Copy link
Contributor

jszwedko commented Apr 7, 2017

I am wondering if we should try to integrate this into the help output for flags with the FilePath defined.

@bradrydzewski
Copy link
Contributor Author

Thanks for the review! I'll plan on updating the pr accordingly this coming week

My only thought is that we may want to more explicitly document in the README what the order of precedence of the sources is (I was surprised we didn't already, but it feels prudent to do so now given the addition of the new source).

I can certainly add this to the documentation.

I also meant to solicit feedback on precedence. Should it be Flag > Env > File? Or Flag > File > Env? Given the primary use case for loading parameters from file (secrets) it made me wonder whether or not it should take precedence over environment, although I'll admit I'm having difficulty articulating why one would be more important than the other. Any thoughts?

@bradrydzewski
Copy link
Contributor Author

bradrydzewski commented Apr 10, 2017

My only thought is that we may want to more explicitly document in the README what the order of precedence of the sources is

I added a section to document precedence for the file path. Let me know if you have any thoughts or feedback on the wording (writing good documentation is harder than writing code, IMO 😄 )

I am wondering if we should try to integrate this into the help output for flags with the FilePath defined.

I also added the filepath to help. Below is an example output. Please let me know if you have any feedback regarding the formatting.

GLOBAL OPTIONS:
   --password  password for the mysql database [/var/secret/password]

@bradrydzewski
Copy link
Contributor Author

bradrydzewski commented Apr 10, 2017

ok, updated the PR based on feedback. Please note that a few of the Travis builders are failing for reasons that I can't explain. I noticed these same builders (Go 1.5 and Go 1.6) are also failing for #616 and #618 as well.

@bradrydzewski
Copy link
Contributor Author

bradrydzewski commented Apr 18, 2017

friendly ping @jszwedko ... I'm sure you are busy so I want to do as much as I can on my end to help push this through. I think the PR addresses most (all?) of your comments, but it looks like travis is acting up. For the life of me I can't figure out what is going on. Any thoughts?

Thanks so much!!

@jszwedko
Copy link
Contributor

Hi @bradrydzewski,

Apologies for the delay in reviewing this! This looks good to me.

Regarding the build failures, this appears to be due to some incompatibilities in the golang.org/x/tools tree for some Go versions. I'm working on fixing this over in #624. I'll drop a note here when that is merged.

@jszwedko
Copy link
Contributor

#624 has been merged, updating this branch

@jszwedko
Copy link
Contributor

And we're green, thanks again @bradrydzewski !

@jszwedko
Copy link
Contributor

Actually, I have one more thought 😄

The other fields that are like this, e.g. EnvVar, support multiple values. What do you think about having FilePaths be a []string so that users could specify multiple files (e.g. []string{"~/.mysql_password", "/etc/mysql/password"}) where it would try them until it found one to read from.

@bradrydzewski
Copy link
Contributor Author

yes, I'll update the pull request next week with that capability. Thanks!

@bradrydzewski
Copy link
Contributor Author

closing now that #675 was merged (thanks @jmccann )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants