cmd

package
v0.0.0-...-3b1aa48 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Defines the cli-interface commands available to the user.

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "locallhost",
	Short: "Run locallhost server",
	Long:  `Start a server on a configured port that returns info about http requests.`,
	Run: func(cmd *cobra.Command, args []string) {
		port := RootConfig.Port
		if port <= 0 {
			port = 8080
			log.Warn().Msgf("Invalid port num %d, defaulting to %d", RootConfig.Port, port)
		}

		logInterfaces(port)

		log.Fatal().Err(server.Serve(port)).Msg("server encountered error")
	},
}

RootCmd represents the base command when called without any subcommands.

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Get version",
	Long:  `Get the current version of tool`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(RootCmd.Use + "+ Version: " + version)
		info, ok := debug.ReadBuildInfo()
		if !ok {
			log.Fatal().Msg("could not read build info")
		}
		stamp := retrieveStamp(info)
		fmt.Printf("  Built with %s on %s\n", stamp.InfoGoCompiler, stamp.InfoBuildTime)
		fmt.Printf("  VCS revision: %s\n", stamp.VCSRevision)
		fmt.Printf("  Go version %s, GOOS %s, GOARCH %s\n", info.GoVersion, stamp.InfoGOOS, stamp.InfoGOARCH)
		fmt.Print("  Dependencies:\n")
		for _, mod := range retrieveDepends(info) {
			fmt.Printf("    %s\n", mod)
		}

	},
}

Print out versions of packages in use. Chore() - Updated manually.

Functions

func Colorize

func Colorize(input interface{}, colorNum int, disabled bool) string

Colorize function from zerolog console.go file to replicate their coloring functionality. Source: https://github.com/rs/zerolog/blob/a21d6107dcda23e36bc5cfd00ce8fdbe8f3ddc23/console.go#L389 Replicated here because it's a private function.

func ConfigureLogger

func ConfigureLogger(debug bool)

func Execute

func Execute(ver string)

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func InitConfig

func InitConfig()

InitConfig reads in config file and ENV variables if set.

func SetupLogger

func SetupLogger(enableColor bool) zerolog.Logger

Configure zerolog with some defaults and cleanup error formatting.

Types

type CmdRootOptions

type CmdRootOptions struct {
	// log more information about what the tool is doing. Overrides --loglevel
	Debug bool
	// set log level
	LogLevel string
	// enable colorized output (default true). Set to false to disable")
	Color bool
	// HTTP port to listen on
	Port int
}

Default options that are available to all commands.

var RootConfig CmdRootOptions

type Stamp

type Stamp struct {
	InfoGoVersion  string
	InfoGoCompiler string
	InfoGOARCH     string
	InfoGOOS       string
	InfoBuildTime  string
	VCSRevision    string
}

Jump to

Keyboard shortcuts

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