env

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 20 Imported by: 0

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

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

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

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

func Get(name string) string

func Getenv

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

Getenv tries retrieving successive keys from os environment variables.

func Getshell

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

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

Getvar retrieves an environment variable.

func GoTime

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

func Listing(w io.Writer)

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

func OpenFile

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

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

func ParseKeywordBool

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

func Pget

func Pget(name string) (string, error)

func Pipe

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

Pipe starts a command and returns its input for writing.

func Pset

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

Pset sets a p variable.

func Ptoggle

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

Ptoggle toggles a p variable.

func Pwrite

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

func Set(name, value string) error

Set sets a variable.

func Shell

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

func TermGraphics() rasterm.TermType

TermGraphics returns the rasterm.TermType based on

func Unquote

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

func Unset(name string) error

Unset unsets a variable.

func ValidIdentifier

func ValidIdentifier(n string) error

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

Types

type Vars

type Vars map[string]string

Vars is a map of variables to their values.

func All

func All() Vars

All returns all variables.

func Pall

func Pall() Vars

Pall returns all p variables.

func (Vars) All

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

All returns all variables as a map.

func (Vars) Set

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

Set sets a variable name.

func (Vars) Unset

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