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

MYST-688 Start having subcommands of "mysterium_node" #316

Merged

Conversation

Waldz
Copy link
Member

@Waldz Waldz commented Aug 23, 2018

Output of bin/build && bin/run --help

NAME:
   mysterium_node - VPN server and client for Mysterium Network https://mysterium.network/

USAGE:
   mysterium_node [global options] command [command options] [arguments...]

VERSION:
   source.dev-build

AUTHOR:
   The "MysteriumNetwork/node" Authors <mysterium-dev@mysterium.network>

COMMANDS:
     version  Show version
     license  Show license
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --data-dir value                 Data directory containing keystore & other persistent files (default: "/Users/waldz/.mysterium")
   --config-dir value               Configs directory containing all configuration, script and helper files (default: "/Users/waldz/workspace/go/src/github.com/mysterium/node/build/node/config")
   --runtime-dir value              Runtime writable directory for temp files (default: "/Users/waldz/workspace/go/src/github.com/mysterium/node/build/node")
   --tequilapi.address value        IP address of interface to listen for incoming connections (default: "127.0.0.1")
   --tequilapi.port value           Port for listening incoming api requests (default: 4050)
   --testnet                        Defines test network configuration
   --localnet                       Defines network configuration which expects localy deployed broker and discovery services
   --discovery-address value        Address (URL form) of discovery service (default: "https://testnet-api.mysterium.network/v1")
   --broker-address value           Address (IP or domain name) of message broker (default: "testnet-broker.mysterium.network")
   --ether.client.rpc value         Url or IPC socket to connect to ethereum node, anything what ethereum client accepts - works (default: "https://ropsten.infura.io")
   --ether.contract.payments value  Address of payments contract (default: "0xbe5F9CCea12Df756bF4a5Baf4c29A10c3ee7C83B")
   --openvpn.binary value           openvpn binary to use for Open VPN connections (default: "openvpn")
   --ipify-url value                Address (URL form) of ipify service (default: "https://api.ipify.org/")
   --location.database value        Service location autodetect database of GeoLite2 format e.g. http://dev.maxmind.com/geoip/geoip2/geolite2/ (default: "GeoLite2-Country.mmdb")
   --cli                            Run an interactive CLI based Mysterium UI
   --help, -h                       show help
   --version, -v                    print the version

COPYRIGHT:
   Mysterium Node Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
This program comes with ABSOLUTELY NO WARRANTY; for details run command 'license --warranty'.
This is free software, and you are welcome to redistribute it
under certain conditions; run command 'license --conditions' for details.

@Waldz Waldz requested a review from a team August 23, 2018 01:30
@Waldz Waldz requested a review from tadovas as a code owner August 23, 2018 01:30
@Waldz Waldz changed the title MYST-688 Integrate cli subcommands tool MYST-688 Start having subcommands of executable Aug 23, 2018
@Waldz Waldz changed the title MYST-688 Start having subcommands of executable MYST-688 Start having subcommands of "mysterium_node" Aug 23, 2018
@Waldz Waldz force-pushed the feature/MYST-688-executable-subcommands branch 2 times, most recently from d0ea62b to 05d6d1f Compare August 23, 2018 01:48
cmd/network.go Outdated
@@ -109,3 +69,46 @@ func ParseNetworkOptions(flags *flag.FlagSet, options *NetworkOptions) {
"Address of payments contract",
)
}

// RegisterNetworkFlags function register directory options to flag set
func RegisterNetworkFlags(flags *[]cli.Flag, options *node.NodeOptions) error {
Copy link
Member

Choose a reason for hiding this comment

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

No error can be returned from the function, we can remove 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.

fixed

cmd/network.go Outdated
},
cli.BoolFlag{
Name: "localnet",
Usage: "Defines network configuration which expects localy deployed broker and discovery services",
Copy link
Member

Choose a reason for hiding this comment

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

typo: locally

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

if err := cmd.RegisterDirectoryFlags(&app.Flags, &options); err != nil {
return app, err
}
app.Flags = append(app.Flags, tequilapiAddressFlag, tequilapiPortFlag)
Copy link
Member

Choose a reason for hiding this comment

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

I'd moved this append after the if block, to make it more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Improved flag registration


import (
"testing"

Copy link
Member

Choose a reason for hiding this comment

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

nitpicking: extra spaces in imports.

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


import (
"testing"

Copy link
Member

Choose a reason for hiding this comment

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

nitpicking: extra spaces in imports.

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

func (options *DirectoryOptions) Check() error {
err := ensureDirExists(options.Config)
// RegisterDirectoryFlags function register directory options to flag set
func RegisterDirectoryFlags(flags *[]cli.Flag, options *node.NodeOptions) error {
Copy link
Member

Choose a reason for hiding this comment

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

* for flags can be omitted here, slice already a reference type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried, but did not succeed pass wo reference sign &

Copy link
Member

Choose a reason for hiding this comment

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

just removing all & and * solves the problem.
like following:
image

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 I tried, but in that cases, values is appended to copies :/

Copy link
Member

Choose a reason for hiding this comment

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

OK, got it. Sorry for confusing.

@@ -19,20 +19,25 @@ package main

import (
"fmt"
"os"
"path/filepath"

Copy link
Member

Choose a reason for hiding this comment

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

nitpicking: extra spaces in imports.

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

package node

// NodeOptions describes options which are required to start Command
type NodeOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

type name will be used as node.NodeOptions by other packages, and that stutters; consider calling this Options (golint)

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

app.Copyright = licenseCopyright

if err := cmd.RegisterDirectoryFlags(&app.Flags, &options); err != nil {
return app, err
Copy link
Contributor

@tadovas tadovas Aug 23, 2018

Choose a reason for hiding this comment

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

Is it intentional to return app object and not-nil error? Normal go convensions say that in case of error - returned object contains undefined state and should not be used (from caller perspective)

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 to return nil, err

@@ -30,7 +30,8 @@ const seewayLogXmlConfig = `
</seelog>
`

func init() {
// Bootstrap loads seelog package into the overall system
func Bootstrap() {
Copy link
Contributor

@tadovas tadovas Aug 23, 2018

Choose a reason for hiding this comment

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

why explicit Bootstrap calling is better when previous init() way? Init is guaranteed to be called only once per whole program. Bootstrap can be called in multiple places by different packages - and introduce very interesting side effects if not carefully used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Longer is very angry of such hack then you include package with _

Copy link
Member Author

@Waldz Waldz Aug 23, 2018

Choose a reason for hiding this comment

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

That practice is allowed only in tests.go or main.go

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see. In that case - let's Bootstrap instead of init

@tadovas
Copy link
Contributor

tadovas commented Aug 23, 2018

All in all - nice 👍

Copy link
Contributor

@tadovas tadovas left a comment

Choose a reason for hiding this comment

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

Please address @soffokl comments too

@Waldz Waldz force-pushed the feature/MYST-688-executable-subcommands branch from 05d6d1f to c6b6094 Compare August 23, 2018 13:15
return err
}

*flags = append(*flags, tequilapiAddressFlag, tequilapiPortFlag)
Copy link
Member

Choose a reason for hiding this comment

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

I was talking about moving all appends together:

 	cmd.RegisterNetworkFlags(flags, &options)

	*flags = append(*flags, tequilapiAddressFlag, tequilapiPortFlag)
 	*flags = append(*flags, openvpnBinaryFlag, ipifyUrlFlag, locationDatabaseFlag)
	*flags = append(*flags, cliFlag)

Copy link
Member Author

Choose a reason for hiding this comment

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

But I want to keep specific order of flags

Copy link
Member

Choose a reason for hiding this comment

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

oh, clear

return app, nil
}

func registerFlags(flags *[]cli.Flag) error {
Copy link
Member

Choose a reason for hiding this comment

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

Please, take a look on comment here.

func (options *DirectoryOptions) Check() error {
err := ensureDirExists(options.Config)
// RegisterDirectoryFlags function register directory options to flag set
func RegisterDirectoryFlags(flags *[]cli.Flag, options *node.Options) error {
Copy link
Member

Choose a reason for hiding this comment

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

Please, take a look on comment here.

@@ -109,3 +69,46 @@ func ParseNetworkOptions(flags *flag.FlagSet, options *NetworkOptions) {
"Address of payments contract",
)
}

// RegisterNetworkFlags function register directory options to flag set
func RegisterNetworkFlags(flags *[]cli.Flag, options *node.Options) {
Copy link
Member

Choose a reason for hiding this comment

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

Please, take a look on comment here.

@Waldz Waldz force-pushed the feature/MYST-688-executable-subcommands branch 2 times, most recently from ae62894 to 4eee4b0 Compare August 24, 2018 18:56
soffokl
soffokl previously approved these changes Aug 27, 2018
@Waldz Waldz force-pushed the feature/MYST-688-executable-subcommands branch from 298d167 to c028b32 Compare August 28, 2018 11:07
Copy link
Member

@soffokl soffokl left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@Waldz Waldz merged commit de4a89a into mysteriumnetwork:master Aug 28, 2018
@Waldz Waldz deleted the feature/MYST-688-executable-subcommands branch August 28, 2018 11:37
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