gogen

package
v1.11.17 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 13 Imported by: 3 modules, 21 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gogen contains various useful functions for creating Go source code files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddParams added in v1.2.0

func AddParams(fileName *string, makeFile *bool) func(ps *param.PSet) error

AddParams will add standard parameters to the passed ParamSet.

Note that if the filename has no default value then the filename parameter must be set if the file is to be created (if, after parameters are set, makeFile is true). If it does have a value then the option will not be shown in the standard (abridged) help message.

Note also that the makeFile parameter must be set to true. This will panic if it is false.

func ExecGoCmd added in v1.4.0

func ExecGoCmd(ioMode CmdIOType, args ...string)

ExecGoCmd will exec the go program with the supplied arguments. If it detects an error it will report it and exit.

func ExecGoCmdCaptureOutput added in v1.7.0

func ExecGoCmdCaptureOutput(w io.Writer, args ...string)

ExecGoCmdCaptureOutput will exec the go program with the supplied arguments. The command's Stdout is connected to the supplied writer if it is not nil. If it detects an error it will report it and exit.

func ExecGoCmdCaptureOutputNoExit added in v1.8.0

func ExecGoCmdCaptureOutputNoExit(w io.Writer, args ...string) bool

ExecGoCmdCaptureOutputNoExit will exec the go program with the supplied arguments. The command's Stdout is connected to the supplied writer if it is not nil. If it detects an error it will report it and return false. Otherwise it returns true

func ExecGoCmdNoExit added in v1.8.0

func ExecGoCmdNoExit(ioMode CmdIOType, args ...string) bool

ExecGoCmdNoExit will exec the go program with the supplied arguments. If it detects an error it will report it and return false. Otherwise it returns true

func GetGoCmdName added in v1.9.0

func GetGoCmdName() string

GetGoCmdName returns the current Go command name

func GetGopath added in v1.7.0

func GetGopath() string

GetGopath returns the value of the GOPATH variable (strictly the first entry in the list if it is set). If the GOPATH env var is not set then the default value is returned: $HOME/go.

func GetImportPath

func GetImportPath() (string, error)

GetImportPath returns the import path of the current package.

func GetImportPathOrDie added in v1.1.0

func GetImportPathOrDie() string

GetImportPathOrDie returns the import path of the current package. Any failure will cause the program to exit.

func GetModule added in v1.6.0

func GetModule() (string, error)

GetModule returns the name of the current module.

func GetModuleOrDie added in v1.6.0

func GetModuleOrDie() string

GetModuleOrDie returns the name of the current module. Any failure will cause the program to exit.

func GetPackage

func GetPackage() (string, error)

GetPackage returns the name of the current package.

func GetPackageOrDie added in v1.1.0

func GetPackageOrDie() string

GetPackageOrDie returns the name of the current package. Any failure will cause the program to exit.

func MakeFileOrDie

func MakeFileOrDie(filename string) *os.File

MakeFileOrDie creates the file truncating it if it already exists and returning the open file. If an error is detected, it is reported and the program exits. It also checks that the file is a go file and does not have the _test.go suffix.

func MakeTestFileOrDie added in v1.3.0

func MakeTestFileOrDie(filename string) *os.File

MakeTestFileOrDie creates the file truncating it if it already exists and returning the open file. If an error is detected, it is reported and the program exits. It also checks that the file has the _test.go suffix.

func PrintImports added in v1.2.0

func PrintImports(f io.Writer, imps ...string)

PrintImports adds the import statements, if any, one per line to the file

func PrintPreamble

func PrintPreamble(f io.Writer, ps *param.PSet)

PrintPreamble prints the introductory comments for the file to be generated. Note that the package name is not written by this but when the file is created; this is because the go list command fails if any go file is empty when it runs.

func PrintPreambleOrDie deprecated added in v1.1.0

func PrintPreambleOrDie(f io.Writer, ps *param.PSet)

PrintPreambleOrDie prints the introductory comments for the file to be generated.

Deprecated: Use PrintPreamble. This function will not call os.Exit and so is misnamed.

func SetGoCmdName added in v1.9.0

func SetGoCmdName(newPath string) error

SetGoCmdName sets the Go command name to the explicit path. The value given must be an executable program in the PATH or the pathname to an executable program. An error will be returned and the setting left unchanged if no such executable exists.

Types

type CmdIOType added in v1.4.0

type CmdIOType int

CmdIOType This determines whether or not a go subcommand should be run with its output displayed. You can also choose to not show IO on failure

const (
	NoCmdIO CmdIOType = iota
	ShowCmdIO
	NoCmdFailIO
)

func (CmdIOType) IsValid added in v1.4.0

func (v CmdIOType) IsValid() bool

IsValid is a method on the CmdIOType type that can be used to check a received parameter for validity. It compares the value against the boundary values for the type and returns false if it is outside the valid range

Jump to

Keyboard shortcuts

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