Skip to content

Commit

Permalink
solved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed Mar 13, 2019
2 parents 631af8e + 16b1ef5 commit e8296c9
Show file tree
Hide file tree
Showing 113 changed files with 3,861 additions and 1,235 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
*.dylib
*.test
*.out
pkg/node/apps/

.idea/

/skywire.json
/apps/
/skywire/
/skywire/
/local/

pkg/node/apps/
pkg/node/bar/
pkg/node/foo/
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ lint: ## Run linters. Use make install-linters first.
GO111MODULE=on go vet -all ./...

install-linters: ## Install linters
GO111MODULE=on go get -u github.com/FiloSottile/vendorcheck
GO111MODULE=off go get -u github.com/FiloSottile/vendorcheck
# For some reason this install method is not recommended, see https://github.com/golangci/golangci-lint#install
# However, they suggest `curl ... | bash` which we should not do
GO111MODULE=on go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go get -u golang.org/x/tools/cmd/goimports

format: ## Formats the code. Must have goimports installed (use make install-linters).
GO111MODULE=on goimports -w -local github.com/skycoin/skywire ./pkg
Expand Down
152 changes: 60 additions & 92 deletions cmd/skywire-cli/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,105 +11,73 @@ import (
"github.com/skycoin/skywire/pkg/node"
)

type appCmds struct {
root *cobra.Command
list *cobra.Command
start *cobra.Command
stop *cobra.Command
setAuto *cobra.Command
func init() {
rootCmd.AddCommand(
appsCmd,
startAppCmd,
stopAppCmd,
setAppAutostartCmd,
)
}

func newAppCmds() *cobra.Command {
a := &appCmds{}
a.initRoot()
a.initList()
a.initStart()
a.initStop()
a.initAuto()

a.root.AddCommand(a.list)
a.root.AddCommand(a.start)
a.root.AddCommand(a.stop)
a.root.AddCommand(a.setAuto)

return a.root
}

func (a *appCmds) initRoot() {
a.root = &cobra.Command{
Use: "app",
Short: "app management operations",
}
}

func (a *appCmds) initList() {
a.list = &cobra.Command{
Use: "list",
Short: "returns list of apps registered on the node",
Run: func(_ *cobra.Command, _ []string) {
states, err := client().Apps()
catch(err)

w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err = fmt.Fprintln(w, "app\tports\tauto_start\tstatus")
catch(err)

for _, state := range states {
status := "stopped"
if state.Status == node.AppStatusRunning {
status = "running"
}

_, err = fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", state.Name, strconv.Itoa(int(state.Port)), state.AutoStart, status)
catch(err)
var appsCmd = &cobra.Command{
Use: "apps",
Short: "lists apps running on the node",
Run: func(_ *cobra.Command, _ []string) {
states, err := rpcClient().Apps()
catch(err)

w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err = fmt.Fprintln(w, "app\tports\tauto_start\tstatus")
catch(err)

for _, state := range states {
status := "stopped"
if state.Status == node.AppStatusRunning {
status = "running"
}

catch(w.Flush())
},
}
_, err = fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", state.Name, strconv.Itoa(int(state.Port)), state.AutoStart, status)
catch(err)
}
catch(w.Flush())
},
}

func (a *appCmds) initStart() {
a.start = &cobra.Command{
Use: "start [name]",
Short: "starts a Skywire app with given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(client().StartApp(args[0]))
fmt.Println("OK")
},
}
var startAppCmd = &cobra.Command{
Use: "start-app <name>",
Short: "starts an app of given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(rpcClient().StartApp(args[0]))
fmt.Println("OK")
},
}

func (a *appCmds) initStop() {
a.stop = &cobra.Command{
Use: "stop [name]",
Short: "stops a Skywire app with given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(client().StopApp(args[0]))
fmt.Println("OK")
},
}
var stopAppCmd = &cobra.Command{
Use: "stop-app <name>",
Short: "stops an app of given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(rpcClient().StopApp(args[0]))
fmt.Println("OK")
},
}

func (a *appCmds) initAuto() {
a.setAuto = &cobra.Command{
Use: "set-auto [name] [on|off]",
Short: "sets the auto-start flag on a Skywire app with given name",
Args: cobra.MinimumNArgs(2),
Run: func(_ *cobra.Command, args []string) {
var autostart bool
switch args[1] {
case "on":
autostart = true
case "off":
autostart = false
default:
catch(fmt.Errorf("invalid args[1] value: %s", args[1]))
}
catch(client().SetAutoStart(args[0], autostart))
fmt.Println("OK")
},
}
var setAppAutostartCmd = &cobra.Command{
Use: "set-app-autostart <name> (on|off)",
Short: "sets the autostart flag for an app of given name",
Args: cobra.MinimumNArgs(2),
Run: func(_ *cobra.Command, args []string) {
var autostart bool
switch args[1] {
case "on":
autostart = true
case "off":
autostart = false
default:
catch(fmt.Errorf("invalid args[1] value: %s", args[1]))
}
catch(rpcClient().SetAutoStart(args[0], autostart))
fmt.Println("OK")
},
}
9 changes: 4 additions & 5 deletions cmd/skywire-cli/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/skycoin/skywire/pkg/node"
)

func init() {
rootCmd.AddCommand(configCmd)
}

var configCmd = &cobra.Command{
Use: "config [skywire.json]",
Short: "Generate default config file",
Expand Down Expand Up @@ -52,7 +56,6 @@ func defaultConfig() *node.Config {
conf.Apps = []node.AppConfig{
{App: "chat", Version: "1.0", Port: 1, AutoStart: true, Args: []string{}},
{App: "therealssh", Version: "1.0", Port: 2, AutoStart: true, Args: []string{}},
{App: "therealssh-client", Version: "1.0", Port: 22, AutoStart: true, Args: []string{}},
{App: "therealproxy", Version: "1.0", Port: 3, AutoStart: true, Args: []string{"-passcode", passcode}},
}
conf.TrustedNodes = []cipher.PubKey{}
Expand All @@ -79,7 +82,3 @@ func defaultConfig() *node.Config {

return conf
}

func init() {
rootCmd.AddCommand(configCmd)
}
85 changes: 0 additions & 85 deletions cmd/skywire-cli/commands/messaging-discovery.go

This file was deleted.

70 changes: 70 additions & 0 deletions cmd/skywire-cli/commands/messaging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package commands

import (
"context"
"fmt"
"os"
"text/tabwriter"
"time"

"github.com/spf13/cobra"

"github.com/skycoin/skywire/pkg/messaging-discovery/client"
)

func init() {
rootCmd.AddCommand(messagingCmd)
}

var mdAddr string

var messagingCmd = &cobra.Command{
Use: "messaging",
Short: "manage operations with messaging services",
}

func init() {
messagingCmd.PersistentFlags().StringVar(&mdAddr, "addr", "https://messaging.discovery.skywire.skycoin.net", "address of messaging discovery server")

messagingCmd.AddCommand(
mEntryCmd,
mAvailableServersCmd)
}

var mEntryCmd = &cobra.Command{
Use: "entry <node-public-key>",
Short: "fetch entry from messaging-discovery",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
pk := parsePK("node-public-key", args[0])
entry, err := client.NewHTTP(mdAddr).Entry(ctx, pk)
catch(err)
fmt.Println(entry)
},
}

var mAvailableServersCmd = &cobra.Command{
Use: "available-servers",
Short: "fetch available servers from messaging-discovery",
Run: func(_ *cobra.Command, _ []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
entries, err := client.NewHTTP(mdAddr).AvailableServers(ctx)
catch(err)
printAvailableServers(entries)
},
}

func printAvailableServers(entries []*client.Entry) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err := fmt.Fprintln(w, "version\tregistered\tpublic-key\taddress\tport\tconns")
catch(err)
for _, entry := range entries {
_, err := fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%d\n",
entry.Version, entry.Timestamp, entry.Static, entry.Server.Address, entry.Server.Port, entry.Server.AvailableConnections)
catch(err)
}
catch(w.Flush())
}
Loading

0 comments on commit e8296c9

Please sign in to comment.