-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix command of ServiceTypeProxy * add skysocksc subcommand * fix SkysocksClientStop issue | fix status of SkysocksClient * set --pk flag to get skysocks key instead argument * fix reset app launcher config issue
- Loading branch information
Showing
11 changed files
with
271 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Package skysocksc root.go | ||
package skysocksc | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// RootCmd contains commands that interact with the skywire-visor | ||
var RootCmd = &cobra.Command{ | ||
Use: "skysocksc", | ||
Short: "controls for Skysocks client", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Package skysocksc cmd/skywire-cli/commands/skysocksc/skysocks.go | ||
package skysocksc | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc" | ||
"github.com/skycoin/skywire/cmd/skywire-cli/internal" | ||
"github.com/skycoin/skywire/pkg/app/appserver" | ||
) | ||
|
||
var pk string | ||
|
||
func init() { | ||
RootCmd.PersistentFlags().StringVar(&clirpc.Addr, "rpc", "localhost:3435", "RPC server address") | ||
RootCmd.AddCommand( | ||
skysockscStartCmd, | ||
skysockscStopCmd, | ||
skysockscStatusCmd, | ||
) | ||
skysockscStartCmd.Flags().StringVar(&pk, "pk", "", "skysocks server public key") | ||
} | ||
|
||
var skysockscStartCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "start the skysocks-client", | ||
Args: cobra.MinimumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rpcClient, err := clirpc.Client(cmd.Flags()) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
internal.Catch(cmd.Flags(), rpcClient.StartSkysocksClient(pk)) | ||
internal.PrintOutput(cmd.Flags(), nil, "Starting.") | ||
startProcess := true | ||
for startProcess { | ||
time.Sleep(time.Second * 1) | ||
internal.PrintOutput(cmd.Flags(), nil, ".") | ||
states, err := rpcClient.Apps() | ||
internal.Catch(cmd.Flags(), err) | ||
|
||
type output struct { | ||
AppError string `json:"app_error,omitempty"` | ||
} | ||
|
||
for _, state := range states { | ||
if state.Name == "skysocks-client" { | ||
if state.Status == appserver.AppStatusRunning { | ||
startProcess = false | ||
internal.PrintOutput(cmd.Flags(), nil, fmt.Sprintln("\nRunning!")) | ||
} | ||
if state.Status == appserver.AppStatusErrored { | ||
startProcess = false | ||
out := output{ | ||
AppError: state.DetailedStatus, | ||
} | ||
internal.PrintOutput(cmd.Flags(), out, fmt.Sprintln("\nError! > "+state.DetailedStatus)) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
var skysockscStopCmd = &cobra.Command{ | ||
Use: "stop", | ||
Short: "stop the skysocks-client", | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
rpcClient, err := clirpc.Client(cmd.Flags()) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
internal.Catch(cmd.Flags(), rpcClient.StopSkysocksClient()) | ||
internal.PrintOutput(cmd.Flags(), "OK", fmt.Sprintln("OK")) | ||
}, | ||
} | ||
|
||
var skysockscStatusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "skysocks-client status", | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
rpcClient, err := clirpc.Client(cmd.Flags()) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
states, err := rpcClient.Apps() | ||
internal.Catch(cmd.Flags(), err) | ||
|
||
var b bytes.Buffer | ||
w := tabwriter.NewWriter(&b, 0, 0, 5, ' ', tabwriter.TabIndent) | ||
internal.Catch(cmd.Flags(), err) | ||
type appState struct { | ||
Status string `json:"status"` | ||
} | ||
var jsonAppStatus appState | ||
for _, state := range states { | ||
if state.Name == "skysocks-client" { | ||
|
||
status := "stopped" | ||
if state.Status == appserver.AppStatusRunning { | ||
status = "running" | ||
} | ||
if state.Status == appserver.AppStatusErrored { | ||
status = "errored" | ||
} | ||
jsonAppStatus = appState{ | ||
Status: status, | ||
} | ||
_, err = fmt.Fprintf(w, "%s\n", status) | ||
internal.Catch(cmd.Flags(), err) | ||
} | ||
} | ||
internal.Catch(cmd.Flags(), w.Flush()) | ||
internal.PrintOutput(cmd.Flags(), jsonAppStatus, b.String()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.