generate

package
v0.0.0-...-47d8c88 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:  "generate",
	Usage: "Generate config files.",
	Subcommands: []*cli.Command{
		{
			Name:  "hosts",
			Usage: "Generate hosts file for a DNS server",
			Action: func(cCtx *cli.Context) error {

				conf, err := config.ParseFile(cCtx.String("config.path"))
				if err != nil {
					return err
				}
				if err := conf.Validate(); err != nil {
					return err
				}

				hosts, err := conf.GenerateHosts()
				if err != nil {
					return err
				}
				fmt.Print(hosts)
				return nil
			},
		},
		{
			Name:      "hostnames",
			Usage:     "Generate hostnames from host pattern",
			ArgsUsage: "<hostnames>",
			Action: func(cCtx *cli.Context) error {
				if cCtx.NArg() < 1 {
					return errors.New("not enough arguments")
				}

				arg := cCtx.Args().Get(0)
				hostnamesRanges := generators.SplitCommaOutsideOfBrackets(arg)

				var hostnames []string
				for _, hostnamesRange := range hostnamesRanges {
					h := generators.ExpandBrackets(hostnamesRange)
					hostnames = append(hostnames, h...)
				}

				for _, h := range hostnames {
					fmt.Println(h)
				}

				return nil
			},
		},
	},
}

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