Skip to content

Commit

Permalink
Update commands docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Morishiri committed Dec 3, 2020
1 parent 5d92dba commit 545848f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -46,4 +51,4 @@ $ go test -v ./...

```
# go build -o loophole main.go
```
```
4 changes: 2 additions & 2 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down
14 changes: 12 additions & 2 deletions cmd/account_login.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

"github.com/loophole/cli/internal/pkg/token"
Expand All @@ -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)
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/account_logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
35 changes: 35 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 4 additions & 1 deletion cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var localEndpointSpecs lm.LocalHttpEndpointSpecs
var httpCmd = &cobra.Command{
Use: "http <port> [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 <port> 192.168.1.20'`,
Run: func(cmd *cobra.Command, args []string) {
localEndpointSpecs.Host = "127.0.0.1"
if len(args) > 1 {
Expand Down
4 changes: 3 additions & 1 deletion cmd/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var dirCmd = &cobra.Command{
Use: "path <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{
Expand Down

0 comments on commit 545848f

Please sign in to comment.