From 545848f347bcd79d288466157fa9c592783146a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sowa?= Date: Thu, 3 Dec 2020 15:37:50 +0100 Subject: [PATCH] Update commands docs --- README.md | 9 +++++++-- cmd/account.go | 4 ++-- cmd/account_login.go | 14 ++++++++++++-- cmd/account_logout.go | 6 ++++-- cmd/docs.go | 35 +++++++++++++++++++++++++++++++++++ cmd/http.go | 5 ++++- cmd/path.go | 4 +++- 7 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 cmd/docs.go diff --git a/README.md b/README.md index b2e5bd4..a3d41ea 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,12 @@ and following the instructions there, then execute ``` # Forward application running on local port 3000 to the world -$ loophole 3000 +$ loophole http 3000 +``` + +``` +# Forward local directory to the world +$ loophole dir ./my-directory ``` Congrats, you can now share the presented link to the world. @@ -46,4 +51,4 @@ $ go test -v ./... ``` # go build -o loophole main.go -``` \ No newline at end of file +``` diff --git a/cmd/account.go b/cmd/account.go index 5f30ea5..48117f5 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -7,8 +7,8 @@ import ( // accountCmd represents the account command var accountCmd = &cobra.Command{ Use: "account", - Short: "Parent for commands concerning your loophole account. Always use with one of the following: login, logout", - Long: "Parent for commands concerning your loophole account. Always use with one of the following: login, logout", + Short: "Group of comands concerning loophole account", + Long: "Parent for commands concerning your loophole account. Always use with one of subcommands", Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, diff --git a/cmd/account_login.go b/cmd/account_login.go index 2b15900..5250b11 100644 --- a/cmd/account_login.go +++ b/cmd/account_login.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "github.com/loophole/cli/internal/pkg/token" @@ -11,10 +12,19 @@ import ( var loginCmd = &cobra.Command{ Use: "login", Short: "Log in to use your account", - Long: "Log in to use your account", + Long: `Loophole service requires authentication, this command allows you to log in or set up one +in case you don't yet have it. + +Running this command as not logged in user will prompt you to open URL and use the browser to verify your identity. + +Running this command as logged in user will fail, in cae you want to relogin then you need to log out first`, Run: func(cmd *cobra.Command, args []string) { + if !token.IsTokenSaved() { + log.Fatal().Msg("Not logged in, nothing to do") + } + if token.IsTokenSaved() { - log.Fatal().Msg("Already logged in, please logout first to reinitialize login") + log.Fatal().Msg(fmt.Sprintf("Already logged in, please use `%s account logout` first to re-login", os.Args[0])) os.Exit(1) } diff --git a/cmd/account_logout.go b/cmd/account_logout.go index c682ef3..bbd1da5 100644 --- a/cmd/account_logout.go +++ b/cmd/account_logout.go @@ -8,8 +8,10 @@ import ( var logoutCmd = &cobra.Command{ Use: "logout", - Short: "Logout from your account", - Long: "Logout from your account", + Short: "Log out from your account", + Long: `This command deletes all the locally stored tokens which allows you to re-login or simply stay logged out. + +In regular scenario you should not need to use it, as tokens are getting refreshed automatically.`, Run: func(cmd *cobra.Command, args []string) { if !token.IsTokenSaved() { log.Fatal().Msg("Not logged in, nothing to do") diff --git a/cmd/docs.go b/cmd/docs.go new file mode 100644 index 0000000..8a15eb1 --- /dev/null +++ b/cmd/docs.go @@ -0,0 +1,35 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" +) + +// docsCommand represents the completion command +var docsCommand = &cobra.Command{ + Use: "docs", + Short: "Generates docs", + Long: `Generates docs for existing loophole commands and saves them in './docs'. + +Mainly for developers.`, + Hidden: true, + Run: func(cmd *cobra.Command, args []string) { + docsPath := "./docs" + if _, err := os.Stat(docsPath); os.IsNotExist(err) { + os.Mkdir(docsPath, os.ModePerm) + } + err := doc.GenMarkdownTree(rootCmd, docsPath) + if err != nil { + fmt.Printf("Failed to generate docs: %v\n", err) + os.Exit(1) + } + fmt.Printf("Docs succesfully generated in %s\n", docsPath) + }, +} + +func init() { + rootCmd.AddCommand(docsCommand) +} diff --git a/cmd/http.go b/cmd/http.go index 1bbdb49..1450e7c 100644 --- a/cmd/http.go +++ b/cmd/http.go @@ -16,7 +16,10 @@ var localEndpointSpecs lm.LocalHttpEndpointSpecs var httpCmd = &cobra.Command{ Use: "http [host]", Short: "Expose http server on given port to the public", - Long: "Expose http server on host:port to the public", + Long: `Exposes http server running locally, or on locally available machine to the public via loophole tunnel. + +To expose server running locally on port 3000 simply use 'loophole http 3000'. +To expose port running on some local host e.g. 192.168.1.20 use 'loophole http 192.168.1.20'`, Run: func(cmd *cobra.Command, args []string) { localEndpointSpecs.Host = "127.0.0.1" if len(args) > 1 { diff --git a/cmd/path.go b/cmd/path.go index c735817..65dce5c 100644 --- a/cmd/path.go +++ b/cmd/path.go @@ -14,7 +14,9 @@ var dirCmd = &cobra.Command{ Use: "path ", Aliases: []string{"dir", "directory"}, Short: "Expose given directory to the public", - Long: "Expose directory to the public", + Long: `Exposes local directory to the public via loophole tunnel. + +To expose local directory (e.g. /data/my-data) simply use 'loophole path /data/my-data'.`, Run: func(cmd *cobra.Command, args []string) { dirEndpointSpecs.Path = args[0] loophole.ForwardDirectory(lm.ExposeDirectoryConfig{