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

iss#6: implemented logic to determine how skywire-updater finds config file. #7

Merged
merged 12 commits into from
Apr 19, 2019

Conversation

atang152
Copy link
Contributor

Implement services to find config file path based on the following order:

  1. CLI argument,
  2. env,
  3. List of default path: i) working directory, ii) home (.skycoin/skywire/skywire-config.json), iii) local (/usr/local/skycoin/skywire/skywire-config.json).

Code is based on library from Skywire mainnet's internal/pathutil/configpath.go. 'Invalid command' was returned when using the original skywire-update [config-path] code. It turns out that adding subcommands prevents RootCmd from accepting path arguments. Therefore, 'updateCmd' was created so update services can take in an optional path argument.

First contribution. Not sure if it's done correctly but I hope it helps. Thank you.

…following order 1) CLI argument, 2) ENV, 3) List of default path - i) working directory, home (.skycoin/skywire/skywire-config.json), iii) local (/usr/local/skycoin/skywire/skywire-config.json). Code base is based on library from Skywire mainnet's internal/pathutil/configpath.go.
…ult config path is used. Coverage for test is low.
…en using skywire-update [config-path]. It turns out that adding cobra subcommands prevents RootCmd from accepting path arguments. Therefore, 'updateCmd' was created so update services can take an optional argument. Update will be based on config path loaded from the following order: 1) CLI argument 2) env 3) list of default path.
"merged develop_v2 to develop_v1. issue#6 - Refractor skywire-update. 'Invalid command' was returned when using skywire-update [config-path]. It turns out that adding cobra subcommands prevents RootCmd from accepting path arguments. Therefore, 'updateCmd' was created so update services can take an optional argument. Update will be based on config path loaded from the following order: 1) CLI argument 2) env 3) list of default path. "
@jdknives jdknives requested review from evanlinjin and ivcosla April 16, 2019 13:37
Copy link

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Great work on a first PR! Code is very clean and excellent work in general.

However, it would be appreciated if you implement the changes as below.

Additionally, if you can do a PR in skycoin/skywire to move /internal/pathutil to /pkg/util/pathutil, and update this PR accordingly, that will be a plus.

Please contact me on Telegram @evanlinjin regardless.

README.md Outdated Show resolved Hide resolved
README.md Outdated

Usage:
skywire-updater [config-path] [flags]

Choose a reason for hiding this comment

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

I would prefer it if we read the [config-file] via a CLI flag, instead of a new sub-command.  😜

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I was thinking to use CLI flags originally too; I will go back and review the code again and see if I could make this change. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Evan. I made a change to the code. It can now reads in [config-file] via CLI flag instead of having to type a new Cobra subcommand. It turns out that by default Cobra only parses local flags on the target command, any local flags on parent commands are ignored. So by enabling this argument Command.TraverseChildren allows Cobra to parse local flags on each command before executing the target command. Please let me know if this logic is okay. Thanks!

cmd/skywire-updater/commands/gen-config.go Outdated Show resolved Hide resolved
cmd/skywire-updater/commands/gen-config.go Show resolved Hide resolved
cmd/skywire-updater/commands/update.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ivcosla ivcosla left a comment

Choose a reason for hiding this comment

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

This is definitely a very good job!, congrats.

@evanlinjin
Copy link

@atang152 in the future, I would name the branch feature/update-config-logic or something similar.

1) Refractor code to now read in [config-file] via CLI flag instead of using a new Cobra subcommand (As per skycoin#7 (comment)). Previous issue of not being able to accept flag arguments due to addition of subcommand was resolved by enabling Command.TraverseChildren. Enabling TraverseChildren allows Cobra to parse local flags on each command before executing target subcommands.
2) Moved /internal/pathutil to /pkg/util/pathutil
@evanlinjin
Copy link

evanlinjin commented Apr 19, 2019

#7 (comment)

@atang152 The changes that are required are as follows.

  1. Import github.com/skycoin/skywire/pkg/util/pathutil, rather than copying the source to github.com/skycoin/skywire-updater/....
    The command to achieve this (with env GO111MODULE=on) is:

    go get github.com/skycoin/skywire/pkg/util/pathutil@mainnet

    Then you can import this in the code.

  2. Please put UpdaterDefaults() in a more suitable location (in /cmd/skywire-updater/root.go is fine).

@atang152 How is progress with this? Just referencing this here as I see the source comment is outdated.

https://github.com/golang/go/wiki/modules

1) Fixed import path by importing github.com/skycoin/skywire/pkg/util/pathutil, rather than copying the source to github.com/skycoin/skywire-updater/... Done so by using GO111MODULE=on go get github.com/skycoin/skywire/pkg/util/pathutil@mainnet
2) Refractor code to now read in [config-file] via CLI flag instead of using a new Cobra subcommand (As per skycoin#7 (comment)). Previous issue of not being able to accept flag arguments due to addition of subcommand was resolved by enabling Command.TraverseChildren. Enabling TraverseChildren allows Cobra to parse local flags on each command before executing target subcommands.
1) Removed pkg/util/pathutil from src and import it directly from skycoin/skywire instead.
2) Ran GO111MODULE=on go mod vendor to update vendor directory to include all packages needed to build/test based on go.mod and go src code.
cmd/skywire-updater/commands/root.go Outdated Show resolved Hide resolved
Ran goimports with the correct path. Editted Makefile to match Skywire standardize format.
Copy link

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Good work!

@evanlinjin evanlinjin merged commit 8e77fa0 into skycoin:develop Apr 19, 2019
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.

3 participants