Skip to content

Commit

Permalink
feat: verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolio-deb committed Oct 26, 2022
1 parent 3f5426a commit 036f7ac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
65 changes: 37 additions & 28 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,23 @@ func main() {
Suggest: true,
Name: "fvpn",
Usage: "fast, secure, and modern VPN",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Usage: "make commands more talkative",
Value: false,
Destination: &utils.Verbose,
},
},
Commands: []*cli.Command{
{
Name: "account",
Usage: "Manage your account",
Usage: "manage ForestVPN accounts",
Subcommands: []*cli.Command{
{
Name: "ls",
Usage: "See local accounts ever logged in",
Usage: "see local accounts ever logged in",
Action: func(c *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand All @@ -89,7 +98,7 @@ func main() {
},
{
Name: "status",
Usage: "See logged-in account info",
Usage: "see logged-in account info",
Action: func(c *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -145,19 +154,19 @@ func main() {
},
{
Name: "register",
Usage: "Sign up to use ForestVPN",
Usage: "create a new ForestVPN account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "email",
Destination: &email,
Usage: "Your email address",
Usage: "your email address",
Value: "",
Aliases: []string{"e"},
},
&cli.StringFlag{
Name: "password",
Destination: &password,
Usage: "Password must be at least 8 characters long",
Usage: "password must be at least 8 characters long",
Value: "",
Aliases: []string{"p"},
},
Expand Down Expand Up @@ -186,19 +195,19 @@ func main() {
},
{
Name: "login",
Usage: "Log into your ForestVPN account",
Usage: "log into your ForestVPN account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "email",
Destination: &email,
Usage: "Your email address",
Usage: "your email address",
Value: "",
Aliases: []string{"e"},
},
&cli.StringFlag{
Name: "password",
Destination: &password,
Usage: "Your password",
Usage: "your password",
Value: "",
Aliases: []string{"p"},
},
Expand All @@ -221,7 +230,7 @@ func main() {
},
{
Name: "logout",
Usage: "Log out from your ForestVPN account on this device",
Usage: "unlink this device from your ForstVPN account",
Action: func(c *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -281,12 +290,12 @@ func main() {
},
{
Name: "state",
Usage: "Control the state of connection",
Usage: "control the state of the ForestVPN connection",
Subcommands: []*cli.Command{
{

Name: "up",
Usage: "Connect to the ForestVPN",
Usage: "connect to the ForestVPN location",
Action: func(c *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -366,8 +375,7 @@ func main() {
},
{
Name: "down",
Description: "Disconnect from ForestVPN",
Usage: "Shut down the connection",
Description: "disconnect from the ForestVPN location",
Action: func(ctx *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -404,9 +412,8 @@ func main() {
},
},
{
Name: "status",
Description: "See wether connection is active",
Usage: "Check the status of the connection",
Name: "status",
Usage: "see wether connection is active",
Action: func(ctx *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -445,11 +452,11 @@ func main() {
},
{
Name: "location",
Usage: "Manage locations",
Usage: "manage ForestVPN locations",
Subcommands: []*cli.Command{
{
Name: "status",
Usage: "See the location is set as default VPN connection",
Usage: "see the location is set as default location to connect",
Action: func(cCtx *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -477,7 +484,7 @@ func main() {
},
{
Name: "set",
Usage: "Set the default location by specifying `UUID` or `Name`",
Usage: "set the default location by specifying `UUID` or `Name`",
Action: func(cCtx *cli.Context) error {
if !auth.IsAuthenticated() {
fmt.Println("Are you logged in?")
Expand Down Expand Up @@ -589,14 +596,13 @@ func main() {
},
},
{
Name: "ls",
Description: "List locations",
Usage: "Show available locations",
Name: "ls",
Usage: "show available ForestVPN locations",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "country",
Destination: &country,
Usage: "Show locations by country",
Usage: "show locations by specific country",
Value: "",
Aliases: []string{"c"},
Required: false,
Expand Down Expand Up @@ -627,9 +633,12 @@ func main() {

if err != nil {
sentry.CaptureException(err)
caser := cases.Title(language.AmericanEnglish)
msg := strings.Split(err.Error(), " ")
msg[0] = caser.String(msg[0])
fmt.Println(strings.Join(msg, " "))

if utils.Verbose {
caser := cases.Title(language.AmericanEnglish)
msg := strings.Split(err.Error(), " ")
msg[0] = caser.String(msg[0])
fmt.Println(strings.Join(msg, " "))
}
}
}
8 changes: 7 additions & 1 deletion src/utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/hashicorp/go-retryablehttp"
)

var Verbose bool

// ip2Net is a function for converting an IP address value, e.g. 127.0.0.1, into a network with mask of 24 bits, e.g. 127.0.0.0/24.
func ip2Net(ip string) string {
return strings.Join(strings.Split(ip, ".")[:3], ".") + ".0/24"
Expand Down Expand Up @@ -225,6 +227,10 @@ func GetLocalTimezone() (string, error) {
func GetHttpClient(retries int) *http.Client {
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = retries
retryClient.Logger = nil

if !Verbose {
retryClient.Logger = nil
}

return retryClient.StandardClient()
}

0 comments on commit 036f7ac

Please sign in to comment.