subcmd

package
v0.0.0-...-8fa1bb7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ServerConfigFile = "serverconfig.json"

ServerConfigFile specifies the file name of the JSON-encoded ServerConfig.

Variables

View Source
var SetupServerFiles = []string{
	"Writers",
	"public.upspinkey",
	"secret.upspinkey",
	ServerConfigFile,
}

SetupServerFiles specifies the configuration files that 'upspin setupserver' should send to the upspinserver.

Functions

func BoolFlag

func BoolFlag(fs *flag.FlagSet, name string) bool

BoolFlag returns the value of the named boolean flag in the flag set.

func HasGlobChar

func HasGlobChar(pattern string) bool

HasGlobChar reports whether the string contains an unescaped Glob metacharacter.

func IntFlag

func IntFlag(fs *flag.FlagSet, name string) int

IntFlag returns the value of the named integer flag in the flag set.

func StringFlag

func StringFlag(fs *flag.FlagSet, name string) string

StringFlag returns the value of the named string flag in the flag set.

func Tilde

func Tilde(file string) string

Tilde processes a leading tilde, if any, in the local file name. If the file name does not begin with a tilde, Tilde returns the argument unchanged. This special processing (only) is applied to all local file names passed to functions in this package. If the target user does not exist, it returns the original string.

Types

type ServerConfig

type ServerConfig struct {
	// Addr specifies the public host and port of the upspinserver.
	Addr upspin.NetAddr

	// User specifies the user name that the upspinserver will run as.
	User upspin.UserName

	// StoreConfig specifies the configuration options for the StoreServer.
	StoreConfig []string
}

ServerConfig describes the configuration of an upspinserver.

type State

type State struct {
	Name        string        // Name of the subcommand we are running.
	Config      upspin.Config // Config; may be nil.
	Client      upspin.Client // Client; may be nil.
	Interactive bool          // Whether the command is line-by-line.
	Stdin       io.Reader     // Where to read standard input
	Stdout      io.Writer     // Where to write standard output.
	Stderr      io.Writer     // Where to write error output.
	ExitCode    int           // Exit with non-zero status for minor problems.
}

State describes the state of a subcommand. See the comments for Exitf to see how Interactive is used. It allows a program to run multiple commands.

func NewState

func NewState(name string) *State

NewState returns a new State for the named subcommand.

func (*State) AtSign

func (s *State) AtSign(file string) upspin.PathName

AtSign processes a leading at sign, if any, in the Upspin file name and replaces it with the current user name. The name must be strictly "@" or begin with "@/", possibly with a suffix ("@+snapshot", "@+camera/"). (If the user name ready has a suffix and the file starts @+suffix, the returned user name appends the suffix from the argument.) Unlike Tilde, it does not look up others user's roots. The argument is of type string; once a file becomes an upspin.PathName it should not be passed to this function. If the file name does not begin with an at sign, AtSign returns the argument unchanged except for promotion to upspin.PathName. If the target user does not exist, it returns the original string.

func (*State) CreateLocal

func (s *State) CreateLocal(path string) *os.File

CreateLocal creates a file on local disk.

func (*State) DefaultIO

func (s *State) DefaultIO()

func (*State) DirServer

func (s *State) DirServer(name upspin.PathName) upspin.DirServer

DirServer returns the DirServer for the root of the name, or exits on failure.

func (*State) Exit

func (s *State) Exit(err error)

Exit calls s.Exitf with the error.

func (*State) ExitNow

func (s *State) ExitNow()

ExitNow terminates the process with the current ExitCode.

func (*State) Exitf

func (s *State) Exitf(format string, args ...interface{})

Exitf prints the error and exits the program. If we are interactive, it calls panic("exit"), which is intended to be recovered from by the calling interpreter. We don't use log (although the packages we call do) because the errors are for regular people.

func (*State) Fail

func (s *State) Fail(err error)

Fail calls s.Failf with the error.

func (*State) Failf

func (s *State) Failf(format string, args ...interface{})

Failf logs the error and sets the exit code. It does not exit the program.

func (*State) GlobAllUpspin

func (s *State) GlobAllUpspin(args []string) []*upspin.DirEntry

GlobAllUpspin processes the arguments, which should be Upspin paths, expanding glob patterns.

func (*State) GlobAllUpspinPath

func (s *State) GlobAllUpspinPath(args []string) []upspin.PathName

GlobAllUpspinPath processes the arguments, which should be Upspin paths, expanding glob patterns. It returns just the paths.

func (*State) GlobLocal

func (s *State) GlobLocal(pattern string) []string

GlobLocal glob-expands the argument, which should be a syntactically valid Glob pattern (including a plain file name). If the pattern is erroneous or matches no files, the function exits.

func (*State) GlobOneLocal

func (s *State) GlobOneLocal(pattern string) string

GlobOneLocal glob-expands the argument, which must result in a single local file name. If not, it exits.

func (*State) GlobOneUpspinPath

func (s *State) GlobOneUpspinPath(pattern string) upspin.PathName

GlobOneUpspin glob-expands the argument, which must result in a single Upspin path.

func (*State) GlobUpspin

func (s *State) GlobUpspin(pattern string) []*upspin.DirEntry

GlobUpspin glob-expands the argument, which must be a syntactically valid Upspin glob pattern (including a plain path name). If the path does not exist or the pattern matches no paths, the function exits.

func (*State) GlobUpspinPath

func (s *State) GlobUpspinPath(pattern string) []upspin.PathName

GlobUpspinPath glob-expands the argument, which must be a syntactically valid Upspin glob pattern (including a plain path name). It returns just the path names. If the pattern matches no paths, the function exits.

func (*State) Init

func (s *State) Init(config upspin.Config)

Init initializes the config and client for the State.

func (*State) KeyServer

func (s *State) KeyServer() upspin.KeyServer

KeyServer returns the KeyServer for the root of the name, or exits on failure.

func (*State) MkdirAllLocal

func (s *State) MkdirAllLocal(path string)

MkdirAllLocal creates a directory on local disk. It creates as much of the path as is necessary.

func (*State) MkdirLocal

func (s *State) MkdirLocal(path string)

MkdirLocal creates a directory on local disk. It requires all but the last element to be present.

func (*State) OpenLocal

func (s *State) OpenLocal(path string) *os.File

OpenLocal opens a file on local disk.

func (*State) ParseFlags

func (s *State) ParseFlags(fs *flag.FlagSet, args []string, help, usage string)

ParseFlags parses the flags in the command line arguments, according to those set in the flag set.

func (*State) ReadAll

func (s *State) ReadAll(fileName string) []byte

ReadAll reads all contents from a local input file or from stdin if the input file name is empty

func (*State) ReadServerConfig

func (s *State) ReadServerConfig(cfgPath string) *ServerConfig

ReadServerConfig reads and JSON-decodes the ServerConfigFile under cfgPath.

func (*State) SetIO

func (s *State) SetIO(stdin io.Reader, stdout, stderr io.Writer)

func (*State) ShouldNotExist

func (s *State) ShouldNotExist(path string)

ShouldNotExist calls s.Exit if the file already exists.

func (*State) WriteServerConfig

func (s *State) WriteServerConfig(cfgPath string, cfg *ServerConfig)

WriteServerConfig JSON-encodes and writes the ServerConfigFile under cfgPath.

Jump to

Keyboard shortcuts

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