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

add --json flag back to vpn and proxy list subcommand #1931

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/skywire-cli/commands/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/app/appserver"
"github.com/skycoin/skywire/pkg/routing"
services "github.com/skycoin/skywire/pkg/servicedisc"
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
Expand Down Expand Up @@ -263,6 +264,7 @@ var statusCmd = &cobra.Command{
}

var isLabel bool
var jsonOutput bool

func init() {
var envServices skywire.EnvServices
Expand All @@ -287,18 +289,28 @@ func init() {
listCmd.Flags().StringVarP(&country, "country", "c", "", "filter results by country")
listCmd.Flags().BoolVarP(&isStats, "stats", "s", false, "return only a count of the results")
listCmd.Flags().BoolVarP(&isLabel, "label", "l", false, "label keys by country \033[91m(SLOW)\033[0m")

listCmd.Flags().BoolVar(&jsonOutput, internal.JSONString, false, "print output in json")
listCmd.Flags().MarkHidden(internal.JSONString) //nolint
}

var listCmd = &cobra.Command{
Use: "list",
Short: "List servers",
Long: fmt.Sprintf("List %v servers from service discovery\n%v/api/services?type=%v\n%v/api/services?type=%v&country=US\n\nSet cache file location to \"\" to avoid using cache files", serviceType, svcDiscURL, serviceType, svcDiscURL, serviceType),
Run: func(_ *cobra.Command, _ []string) {
Run: func(cmd *cobra.Command, _ []string) {
sds := internal.GetData(cacheFileSD, sdURL+"/api/services?type="+serviceType, cacheFilesAge)
if rawData {
script.Echo(string(pretty.Color(pretty.Pretty([]byte(sds)), nil))).Stdout() //nolint
return
}
if jsonOutput {
var list []services.Service
json.Unmarshal([]byte(sds), &list) //nolint
var b bytes.Buffer
internal.PrintOutput(cmd.Flags(), list, b.String())
return
}
if pk != "" {
if isStats {
count, _ := script.Echo(sds).JQ(`map(select(.address == "`+pk+`:3"))`).Replace("\"", "").Replace(":", " ").Column(1).CountLines() //nolint
Expand Down
16 changes: 15 additions & 1 deletion cmd/skywire-cli/commands/vpn/vvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
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"
services "github.com/skycoin/skywire/pkg/servicedisc"
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire/pkg/visor"
)
Expand Down Expand Up @@ -164,6 +165,7 @@ var statusCmd = &cobra.Command{
}

var isLabel bool
var jsonOutput bool

func init() {
var envServices skywire.EnvServices
Expand All @@ -188,18 +190,30 @@ func init() {
listCmd.Flags().StringVarP(&country, "country", "c", "", "filter results by country")
listCmd.Flags().BoolVarP(&isStats, "stats", "s", false, "return only a count of the results")
listCmd.Flags().BoolVarP(&isLabel, "label", "l", false, "label keys by country \033[91m(SLOW)\033[0m")

listCmd.Flags().BoolVar(&jsonOutput, internal.JSONString, false, "print output in json")
listCmd.Flags().MarkHidden(internal.JSONString) //nolint
}

var listCmd = &cobra.Command{
Use: "list",
Short: "List servers",
Long: fmt.Sprintf("List %v servers from service discovery\n%v/api/services?type=%v\n%v/api/services?type=%v&country=US\n\nSet cache file location to \"\" to avoid using cache files", serviceType, sdURL, serviceType, sdURL, serviceType),
Run: func(_ *cobra.Command, _ []string) {
Run: func(cmd *cobra.Command, _ []string) {
sds := internal.GetData(cacheFileSD, sdURL+"/api/services?type="+serviceType, cacheFilesAge)
if rawData {
script.Echo(string(pretty.Color(pretty.Pretty([]byte(sds)), nil))).Stdout() //nolint
return
}

if jsonOutput {
var list []services.Service
json.Unmarshal([]byte(sds), &list) //nolint
var b bytes.Buffer
internal.PrintOutput(cmd.Flags(), list, b.String())
return
}

if pk != "" {
if isStats {
count, _ := script.Echo(sds).JQ(`map(select(.address == "`+pk+`:3"))`).Replace("\"", "").Replace(":", " ").Column(1).CountLines() //nolint
Expand Down
Loading