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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -98,12 +98,13 @@ dep ensure
* Add new package to project
```bash
dep ensure -add github.com/ccding/go-stun
dep ensure -add github.com/ccding/go-stun@^0.1.0
```

* Update package in project
```bash
vim Gopkg.toml
dep ensure
dep ensure -update
```

## Creating pull request
Expand Down
15 changes: 12 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Expand Up @@ -68,3 +68,7 @@
[[prune.project]]
name = "github.com/ethereum/go-ethereum"
unused-packages = false

[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"
2 changes: 1 addition & 1 deletion bin/run
@@ -1,5 +1,5 @@
#!/bin/bash

sudo ./build/client/mysterium_client \
sudo ./build/node/mysterium_node \
--localnet \
$@
Expand Up @@ -24,9 +24,9 @@ import (
"strings"

"github.com/chzyer/readline"
node_cmd "github.com/mysterium/node/cmd"
"github.com/mysterium/node/metadata"
tequilapi_client "github.com/mysterium/node/tequilapi/client"
"github.com/mysterium/node/utils"
)

// NewCommand constructs CLI based with possibility to control quiting
Expand Down Expand Up @@ -301,7 +301,7 @@ func (c *Command) help() {

// quit stops cli and client commands and exits application
func (c *Command) quit() {
stop := node_cmd.HardKiller(c.Kill)
stop := utils.HardKiller(c.Kill)
stop()
}

Expand Down
60 changes: 60 additions & 0 deletions cmd/commands/license/command.go
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package license

import (
"fmt"

"github.com/mysterium/node/metadata"
"github.com/urfave/cli"
)

var (
licenseWarrantyFlag = cli.BoolFlag{
Name: "warranty",
Usage: "Show details of license warranty",
}
licenseConditionsFlag = cli.BoolFlag{
Name: "conditions",
Usage: "Show details of license conditions",
}
)

// NewCommand function creates license command
func NewCommand(licenseCopyright string) *cli.Command {
return &cli.Command{
Name: "license",
Usage: "Show license",
ArgsUsage: " ",
Flags: []cli.Flag{licenseWarrantyFlag, licenseConditionsFlag},
Action: func(ctx *cli.Context) error {
if ctx.IsSet(licenseWarrantyFlag.Name) {
_, err := fmt.Fprintln(ctx.App.Writer, metadata.LicenseWarranty)
return err
}

if ctx.IsSet(licenseConditionsFlag.Name) {
_, err := fmt.Fprintln(ctx.App.Writer, metadata.LicenseConditions)
return err
}

_, err := fmt.Fprintln(ctx.App.Writer, licenseCopyright)
return err
},
}
}
40 changes: 40 additions & 0 deletions cmd/commands/license/command_test.go
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package license

import (
"bytes"
"flag"
"testing"

"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)

func TestCommandRun(t *testing.T) {
output := bytes.NewBufferString("")

command := NewCommand("super license")
command.Run(cli.NewContext(
&cli.App{Writer: output},
flag.NewFlagSet("test", 0),
nil,
))

assert.Equal(t, "super license\n", output.String())
}
44 changes: 44 additions & 0 deletions cmd/commands/run/command.go
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package run

import (
"github.com/mysterium/node/cmd"
"github.com/mysterium/node/core/node"
"github.com/mysterium/node/utils"
"github.com/urfave/cli"
)

// NewCommand function creates run command
func NewCommand(options node.Options) *cli.Command {
return &cli.Command{
Name: "run",
Usage: "Runs Mysterium node",
ArgsUsage: " ",
Action: func(ctx *cli.Context) error {
nodeInstance := node.NewNode(options)
cmd.RegisterSignalCallback(utils.SoftKiller(nodeInstance.Kill))

if err := nodeInstance.Start(); err != nil {
return err
}

return nodeInstance.Wait()
},
}
}
122 changes: 0 additions & 122 deletions cmd/commands/run/options.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/commands/server/factory.go
Expand Up @@ -24,11 +24,11 @@ import (

log "github.com/cihub/seelog"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/mysterium/node/cmd"
identity_handler "github.com/mysterium/node/cmd/commands/server/identity"
"github.com/mysterium/node/communication"
nats_dialog "github.com/mysterium/node/communication/nats/dialog"
nats_discovery "github.com/mysterium/node/communication/nats/discovery"
"github.com/mysterium/node/core/node"
"github.com/mysterium/node/identity"
"github.com/mysterium/node/identity/registry"
"github.com/mysterium/node/ip"
Expand All @@ -46,7 +46,7 @@ import (
// NewCommand function creates new server command by given options
func NewCommand(options CommandOptions) *Command {

networkDefinition := cmd.GetNetworkDefinition(options.NetworkOptions)
networkDefinition := node.GetNetworkDefinition(options.NetworkOptions)

mysteriumClient := server.NewClient(networkDefinition.DiscoveryAPIAddress)
ipResolver := ip.NewResolver(options.IpifyUrl)
Expand Down