feat: initial commit with cobra setup

This commit is contained in:
2024-10-19 12:26:42 +05:30
commit b4eb561e1f
10 changed files with 190 additions and 0 deletions

30
cmd/client.go Normal file
View File

@ -0,0 +1,30 @@
/*
Copyright © 2024 tux <0xtux@pm.me>
*/
package cmd
import (
"github.com/0xtux/trok/internal/client"
"github.com/spf13/cobra"
)
// clientCmd represents the local command
var clientCmd = &cobra.Command{
Use: "client",
Short: "Initiates a local proxy to the remote server",
Long: "Initiates a local proxy to the remote server",
Run: func(cmd *cobra.Command, args []string) {
port, err := cmd.Flags().GetUint16("port")
if err != nil {
panic(err)
}
client.Start(port)
},
}
func init() {
rootCmd.AddCommand(clientCmd)
clientCmd.Flags().Uint16P("port", "p", 0, "Local port to expose")
clientCmd.MarkFlagRequired("port")
}

24
cmd/root.go Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright © 2024 tux <0xtux@pm.me>
*/
package cmd
import (
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "trok",
Hidden: true,
Long: "Simple TCP tunnel in Go that exposes local ports to internet, bypassing NAT firewalls.",
}
func Execute() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

29
cmd/server.go Normal file
View File

@ -0,0 +1,29 @@
/*
Copyright © 2024 tux <0xtux@pm.me>
*/
package cmd
import (
"github.com/0xtux/trok/internal/server"
"github.com/spf13/cobra"
)
// serverCmd represents the server command
var serverCmd = &cobra.Command{
Use: "server",
Short: "Initiates the remote proxy server",
Long: "Initiates the remote proxy server",
Run: func(cmd *cobra.Command, args []string) {
port, err := cmd.Flags().GetUint16("port")
if err != nil {
panic(err)
}
server.Start(port)
},
}
func init() {
rootCmd.AddCommand(serverCmd)
serverCmd.Flags().Uint16P("port", "p", 1421, "Port for the server to listen on")
}