cmd

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Go = &cli.Command{
		Name:            "go",
		Usage:           "Executes standard go commands with automatic instrumentation enabled",
		UsageText:       "orchestrion go [go command arguments...]",
		Args:            true,
		SkipFlagParsing: true,
		Action: func(c *cli.Context) error {
			pin.AutoPinOrchestrion()

			if err := goproxy.Run(c.Args().Slice(), goproxy.WithToolexec(orchestrionBinPath, "toolexec")); err != nil {
				var exitErr *exec.ExitError
				if errors.As(err, &exitErr) {
					return cli.Exit("", exitErr.ExitCode())
				}
				return cli.Exit(err, -1)
			}
			return nil
		},
	}
)
View Source
var Pin = &cli.Command{
	Name:  "pin",
	Usage: "Registers orchestrion in your project's `go.mod` file",
	Action: func(*cli.Context) error {
		return pin.PinOrchestrion()
	},
}
View Source
var Server = &cli.Command{
	Name:        "server",
	Usage:       "Start an Objectsrion job server.",
	Description: "The job server is used to remove duplicated processing that can occur when instrumenting large applications, due to how Orchestrion injects new dependencies that the go toolchain was initially not aware of.\n\nUsers do not normally need to use this command directly, as Orchestrion automatically manages servers during runtime.",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "url-file",
			Usage: "Write a file containing the ClientURL for this server once it is ready to accept connections. The server automatically shuts down when the URL file is deleted.",
		},
		&cli.IntFlag{
			Name:        "port",
			Usage:       "Choose a port to listen on",
			Value:       -1,
			DefaultText: "random",
		},
		&cli.DurationFlag{
			Name:  "inactivity-timeout",
			Usage: "Automatically shut down after a period without any connected client",
			Value: time.Minute,
		},
		&cli.BoolFlag{
			Name:  "nats-logging",
			Usage: "Enable NATS server logging",
		},
	},
	Hidden: true,
	Action: func(c *cli.Context) error {
		opts := jobserver.Options{
			ServerName:        "github.com/DataDog/orchestrion server",
			Port:              c.Int("port"),
			InactivityTimeout: c.Duration("inactivity-timeout"),
			EnableLogging:     c.Bool("nats-logging"),
		}

		if urlFile := c.String("url-file"); urlFile != "" {
			return startWithURLFile(&opts, urlFile)
		}
		_, err := start(&opts, true)
		return err
	},
}
View Source
var Toolexec = &cli.Command{
	Name:            "toolexec",
	Usage:           "Standard `-toolexec` plugin for the Go toolchain",
	UsageText:       "orchestrion toolexec [tool] [tool args...]",
	Args:            true,
	SkipFlagParsing: true,
	Action: func(c *cli.Context) error {
		proxyCmd, err := proxy.ParseCommand(c.Args().Slice())
		if err != nil {
			return err
		}
		defer proxyCmd.Close()

		if proxyCmd.Type() == proxy.CommandTypeOther {

			return proxy.RunCommand(proxyCmd)
		}

		pin.AutoPinOrchestrion()

		if proxyCmd.ShowVersion() {
			log.Tracef("Toolexec version command: %q\n", proxyCmd)
			fullVersion, err := toolexec.ComputeVersion(proxyCmd)
			if err != nil {
				return err
			}
			log.Tracef("Complete version output: %s\n", fullVersion)
			_, err = fmt.Println(fullVersion)
			return err
		}

		log.Tracef("Toolexec original command: %q\n", proxyCmd.Args())
		weaver := aspect.Weaver{ImportPath: os.Getenv("TOOLEXEC_IMPORTPATH")}

		if err := proxy.ProcessCommand(proxyCmd, weaver.OnCompile); err != nil {
			return err
		}
		if err := proxy.ProcessCommand(proxyCmd, weaver.OnCompileMain); err != nil {
			return err
		}
		if err := proxy.ProcessCommand(proxyCmd, weaver.OnLink); err != nil {
			return err
		}

		log.Tracef("Toolexec final command:    %q\n", proxyCmd.Args())
		return proxy.RunCommand(proxyCmd)
	},
}
View Source
var Version = &cli.Command{
	Name:  "version",
	Usage: "Displays this command's version information",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:    "verbose",
			Aliases: []string{"v"},
			Usage:   "display the version of the orchestrion binary that started this command (if different from the current)",
			Hidden:  true,
		},
	},
	Action: func(c *cli.Context) error {
		if _, err := fmt.Fprintf(c.App.Writer, "orchestrion %s", version.Tag); err != nil {
			return err
		}

		if c.Bool("verbose") {
			if startupVersion := ensure.StartupVersion(); startupVersion != version.Tag {
				if _, err := fmt.Fprintf(c.App.Writer, " (started as %s)", startupVersion); err != nil {
					return err
				}
			}
			if _, err := fmt.Fprintf(c.App.Writer, " built with %s (%s/%s)", runtime.Version(), runtime.GOOS, runtime.GOARCH); err != nil {
				return err
			}
		}

		_, err := fmt.Fprintln(c.App.Writer)
		return err
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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