cmd

package
v0.0.0-...-05a1e4a Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Enter = &cli.Command{
	Name:    "enter",
	Aliases: []string{"run", "e"},
	Usage:   "builds and enters the shell",
	Description: `
	Enter the shell. If extra arguments are passed, run as a command inside
	the development environment instead.
	`,
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "path",
			Usage: "path to the project root",
			Value: "",
		},
		&cli.StringSliceFlag{
			Name:  "I",
			Usage: "Add a path to the NIX_PATH",
			Value: cli.NewStringSlice("devshell=https://github.com/numtide/devshell/archive/main.tar.gz"),
		},
	},
	Action: func(c *cli.Context) error {
		var err error

		args := []string{"--show-trace"}
		path := c.String("path")
		paths := c.StringSlice("I")

		if path == "" {
			path, err = os.Getwd()
			if err != nil {
				return err
			}
		}
		path, err = filepath.Abs(path)
		if err != nil {
			return err
		}

		file, ret := config.Search(path)

		switch ret {
		case config.SearchNix:
			args = append(args, file)
		case config.SearchTOML:
			args = append(args, "--expr", fmt.Sprintf(shellNix, file))
		case config.SearchNone:
			return fmt.Errorf("no devshell found in %s", path)
		}

		for _, p := range paths {
			args = append(args, "-I", p)
		}

		drvPath, err := run("nix-instantiate", args...)
		if err != nil {
			return err
		}

		drvPath = strings.Trim(drvPath, "\"")

		outPath, err := run("nix-store", "--realize", drvPath)
		if err != nil {
			return err
		}

		cmd := exec.Command(outPath, c.Args().Slice()...)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		return cmd.Run()
	},
}

Enter command

View Source
var Init = &cli.Command{
	Name:  "init",
	Usage: "creates a new " + config.FileName + " file",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "name",
			Usage: "name of the project",
		},
		&cli.StringFlag{
			Name:  "path",
			Usage: "project folder",
			Value: ".",
		},
		&cli.BoolFlag{
			Name:  "force",
			Usage: "override the file if it already exists",
		},
	},
	Action: func(c *cli.Context) error {

		p := c.String("path")
		name := c.String("name")
		force := c.Bool("force")

		if name == "" {
			p2, err := filepath.Abs(p)
			if err != nil {
				return err
			}
			name = filepath.Base(p2)
		}

		err := config.Init(p, name, force)
		if err != nil {
			return err
		}
		fmt.Println("config file created")

		return nil
	},
}

Init command

Functions

func Execute

func Execute() error

Execute the main command

Types

This section is empty.

Jump to

Keyboard shortcuts

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