commands

package
v1.3.112 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package commands cmd/skywire-visor/commands/etc.go c4-vis-cli

Package commands cmd/skywire-visor/commands/root.go c4-vis-cli

Package commands is the skywire visor command: its flags, which config file to read, and how the visor is started (alone, with a system tray, or as a tray for a visor running elsewhere).

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use: func() string {
		return strings.Split(filepath.Base(strings.ReplaceAll(strings.ReplaceAll(fmt.Sprintf("%v", os.Args), "[", ""), "]", "")), " ")[0]
	}(),
	Short: "Skywire Visor",
	Long: `
	┌─┐┬┌─┬ ┬┬ ┬┬┬─┐┌─┐
	└─┐├┴┐└┬┘││││├┬┘├┤
	└─┘┴ ┴ ┴ └┴┘┴┴└─└─┘`,
	PreRun: func(cmd *cobra.Command, _ []string) {

		if all {
			for _, j := range hiddenflags {
				f := cmd.Flags().Lookup(j)
				f.Hidden = false
			}

			cmd.Flags().MarkHidden("help")
			if err := cmd.Help(); err != nil {
				cmdutil.Eprintf("Failed to print help: %v\n", err)
			}
			cmdutil.Println("\033[F                            * \u001b[94moverrides config file\u001b[0m")
			cmdutil.Exit(0)
		}

		genCompletion(cmd)

		log := mLog.PackageLogger("pre-run")

		if confArg != "" {
			confPath = "arg"
		} else {
			if stdin {
				confPath = visorconfig.Stdin
			} else {

				if pkg {
					if !root {
						log.Fatal("root permissions required to use the specified config")
					}
					if !pkgconfigexists {
						log.Fatal("config not found")
					}
				}
				if usr {
					if root {
						log.Fatal("cannot use specified config as root")
					}
					if !userconfigexists {
						log.Fatal("config not found")
					}
				}

				if (pkg && usr) || ((pkg || usr) && (confPath != "")) {
					log.Fatal("Error: multiple configs specified")
				}

				if pkg {
					confPath = skyenv.SkywirePath + "/" + skyenv.ConfigJSON
				}

				if usr {
					confPath = visorconfig.HomePath() + "/" + skyenv.ConfigName
				}
				if confPath == "" {

					confPath = skyenv.ConfigName
				}

				if !strings.HasSuffix(confPath, ".json") {
					confPath = confPath + ".json"
				}

				if _, err := os.Stat(confPath); err != nil {

					log.WithError(err).Fatal("config file not found")
				}
			}
		}

		if dmsgServer != "" {
			if i := strings.Index(dmsgServer, "@"); i >= 0 {
				pkPart := dmsgServer[:i]
				addrPart := dmsgServer[i+1:]
				if pkPart == "" || addrPart == "" {
					log.Fatalf("--dmsg-server: invalid pk@host:port form (need both pk and address): %q", dmsgServer)
				}
				var pk cipher.PubKey
				if err := pk.Set(pkPart); err != nil {
					log.WithError(err).Fatalf("--dmsg-server: invalid public key %q", pkPart)
				}
				dmsgServer = pkPart
				dmsgServerAddr = addrPart
			} else {
				var pk cipher.PubKey
				if err := pk.Set(dmsgServer); err != nil {
					log.WithError(err).Fatalf("--dmsg-server: invalid public key %q", dmsgServer)
				}
			}
		}
		logBuildInfo(mLog)
		if launchBrowser {
			hypervisorUI = true
		}

		if skyenv.OS == "linux" {

			if _, err := exec.LookPath("stat"); err == nil {
				c, _ := filepath.Split(confPath)
				if c == "" {
					c = "./"
				}
				owner, err := script.Exec(`stat -c '%U' ` + c).String()
				if err != nil {
					log.Error("cannot stat: " + c)
				}
				rootOwner, err := script.Exec(`stat -c '%U' /root`).String()
				if err != nil {
					log.Error("cannot stat: /root")
				}
				if (owner != rootOwner) && root {
					log.Warn("writing as root to directory not owned by root")
				}
				if !root && (owner == rootOwner) {
					log.Fatal("Insufficient permissions to write to the specified path")
				}
			}
		}
		if runAsSystray {
			if skyenv.OS == "linux" {
				if root {
					log.Warn("Systray cannot start in userspace when visor is run as root")
				}
			}
		}

	},
	Run: func(_ *cobra.Command, _ []string) {
		if runSystrayOnly {
			visor.RunTrayOnly(systrayRPCAddr)
			return
		}
		conf, err := loadConfig()
		if err != nil {
			mLog.PackageLogger("visor:config").WithError(err).Fatal("Failed to load config.")
		}
		if runAsSystray {
			visor.RunSystray(conf, options())
			return
		}
		if err := visor.Run(context.Background(), conf, options()); err != nil {
			mLog.WithError(err).Fatal("a fatal error occurred")
		}
	},
	Version: buildinfo.Version(),
}

RootCmd contains the help command & invocation flags

Functions

func Execute

func Execute()

Execute executes root CLI command.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址