| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | |
| 7 | "github.com/lima-vm/sshocker/pkg/version" |
| 8 | "github.com/sirupsen/logrus" |
| 9 | "github.com/urfave/cli/v2" |
| 10 | ) |
| 11 | |
| 12 | func newApp() *cli.App { |
| 13 | debug := false |
| 14 | app := cli.NewApp() |
| 15 | app.Name = "sshocker" |
| 16 | app.Usage = "ssh + reverse sshfs + port forwarder, in Docker-like CLI" |
| 17 | app.UsageText = "sshocker run -p LOCALIP:LOCALPORT:REMOTEPORT -v LOCALDIR:REMOTEDIR USER@HOST" |
| 18 | |
| 19 | |
| 20 | app.Flags = []cli.Flag{ |
| 21 | &cli.BoolFlag{ |
| 22 | Name: "debug", |
| 23 | Usage: "debug mode", |
| 24 | Destination: &debug, |
| 25 | }, |
| 26 | &cli.BoolFlag{ |
| 27 | Name: "version", |
| 28 | Usage: "print the version", |
| 29 | }, |
| 30 | } |
| 31 | app.Flags = append(app.Flags, setHidden(runFlags, true)...) |
| 32 | app.Before = func(context *cli.Context) error { |
| 33 | if context.Bool("version") { |
| 34 | fmt.Printf("sshocker version %s\n", version.Version) |
| 35 | os.Exit(0) |
| 36 | return nil |
| 37 | } |
| 38 | if debug { |
| 39 | logrus.SetLevel(logrus.DebugLevel) |
| 40 | } |
| 41 | return nil |
| 42 | } |
| 43 | app.Commands = []*cli.Command{runCommand} |
| 44 | app.Action = runAction |
| 45 | return app |
| 46 | } |
| 47 | |
| 48 | func main() { |
| 49 | if err := newApp().Run(os.Args); err != nil { |
| 50 | logrus.Fatal(err) |
| 51 | } |
| 52 | } |