env

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 20 Imported by: 14

Documentation

Overview

Package env contains runtime environment variables for usql, along with various helper funcs to determine the user's configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chdir added in v0.5.0

func Chdir(u *user.User, path string) error

Chdir changes the current working directory to the specified path, or to the user's home directory if path is not specified.

func Dequote added in v0.8.2

func Dequote(s string, quote byte) (string, error)

Dequote unquotes a string.

func EditFile

func EditFile(u *user.User, path, line, s string) ([]rune, error)

EditFile edits a file. If path is empty, then a temporary file will be created.

func Exec added in v0.5.0

func Exec(s string) (string, error)

Exec executes s using the user's SHELL / COMSPEC with -c (or /c) and returning the captured output. See Getshell.

When SHELL or COMSPEC is not defined, then "sh" / "cmd.exe" will be used instead, assuming it is found on the system's PATH.

func Get added in v0.9.0

func Get(name string) string

func Getenv added in v0.6.0

func Getenv(keys ...string) (string, bool)

Getenv tries retrieving successive keys from os environment variables.

func Getshell added in v0.8.2

func Getshell() (string, string)

Getshell returns the user's defined SHELL, or system default (if found on path) and the appropriate command-line argument for the returned shell.

Looks at the SHELL environment variable first, and then COMSPEC/ComSpec on Windows. Defaults to sh on non-Windows systems, and to cmd.exe on Windows.

func Getvar added in v0.5.0

func Getvar(s string, v Vars) (bool, string, error)

Getvar retrieves an environment variable.

func GoTime added in v0.9.1

func GoTime() string

GoTime returns the user's time format converted to Go's time.Format value.

func HistoryFile

func HistoryFile(u *user.User) string

HistoryFile returns the path to the history file.

Defaults to ~/.<command name>_history, overridden by environment variable <COMMAND NAME>_HISTORY (ie, ~/.usql_history and USQL_HISTORY).

func Listing added in v0.13.3

func Listing(w io.Writer)

Listing writes the formatted variables listing to w, separated into different sections for all known variables.

func OpenFile added in v0.5.0

func OpenFile(u *user.User, path string, relative bool) (string, *os.File, error)

OpenFile opens a file for read (os.O_RDONLY), returning the full, expanded path of the file. Callers are responsible for closing the returned file.

func ParseBool added in v0.8.2

func ParseBool(value, name string) (string, error)

func ParseKeywordBool added in v0.9.0

func ParseKeywordBool(value, name string, keywords ...string) (string, error)

func Pget added in v0.7.2

func Pget(name string) (string, error)

func Pipe added in v0.9.0

func Pipe(c string) (io.WriteCloser, *exec.Cmd, error)

Pipe starts a command and returns its input for writing.

func Pset added in v0.7.2

func Pset(name, value string) (string, error)

Pset sets a p variable.

func Ptoggle added in v0.7.2

func Ptoggle(name, extra string) (string, error)

Ptoggle toggles a p variable.

func Pwrite added in v0.8.2

func Pwrite(w io.Writer) error

Pwrite writes the p variables to the writer.

func RCFile

func RCFile(u *user.User) string

RCFile returns the path to the RC file.

Defaults to ~/.<command name>rc, overridden by environment variable <COMMAND NAME>RC (ie, ~/.usqlrc and USQLRC).

func Set added in v0.5.0

func Set(name, value string) error

Set sets a variable.

func Shell added in v0.8.2

func Shell(s string) error

Shell runs s as a shell. When s is empty the user's SHELL or COMSPEC is used. See Getshell.

func TermGraphics added in v0.18.0

func TermGraphics() rasterm.TermType

TermGraphics returns the rasterm.TermType based on TERM_GRAPHICS environment variable.

func Unquote added in v0.5.0

func Unquote(u *user.User, exec bool, v Vars) func(string, bool) (bool, string, error)

Unquote returns a func that unquotes strings for the user.

When exec is true, backtick'd strings will be executed using the provided user's shell (see Exec).

func Unset added in v0.5.0

func Unset(name string) error

Unset unsets a variable.

func ValidIdentifier added in v0.5.0

func ValidIdentifier(n string) error

ValidIdentifier returns an error when n is not a valid identifier.

Types

type Vars added in v0.5.0

type Vars map[string]string

Vars is a map of variables to their values.

func All added in v0.5.0

func All() Vars

All returns all variables.

func Pall added in v0.7.2

func Pall() Vars

Pall returns all p variables.

func (Vars) All added in v0.5.0

func (v Vars) All() map[string]string

All returns all variables as a map.

func (Vars) Set added in v0.5.0

func (v Vars) Set(name, value string)

Set sets a variable name.

func (Vars) Unset added in v0.5.0

func (v Vars) Unset(name string)

Unset unsets a variable name.

Jump to

Keyboard shortcuts

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