Skip to content
Open
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
15 changes: 15 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//go:build !desktop
// +build !desktop

package cmd

import (
"context"
"fmt"
stdlog "log"
"os"
Expand Down Expand Up @@ -61,3 +63,16 @@ func Execute() {
os.Exit(1)
}
}

// GoExecute runs command parsing chain from go.
// Look example ../example/main.go.
func GoExecute(ctx context.Context, version, commit, mode string, args ...string) error {
config.Config.Version = version
config.Config.CommitHash = commit
config.Config.ClientMode = mode

rootCmd.Version = fmt.Sprintf("%s (%s)", config.Config.Version, config.Config.CommitHash)

rootCmd.SetArgs(args)
return rootCmd.ExecuteContext(ctx)
}
22 changes: 22 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"context"
"fmt"
"time"

"github.com/loophole/cli/cmd"
)

func main() {
fmt.Println("Master func")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

fmt.Println("Started loophole tunnel to 127.0.0.1:80")
go cmd.GoExecute(ctx, "development", "unknown", "cli", "--hostname", "slave", "http", "80")

fmt.Println("Started local http server on 127.0.0.1:80")
time.Sleep(time.Second * 30) // Mock server works 30s
fmt.Println("Server stopped")
}