Documentation ¶
Overview ¶
Package wio provides API to customize your command-line application written using WIO (Whole-In-One to Go).
You don't need to care most of them, because wio command cares on befalf of you.
See https://github.com/Maki-Daisuke/go-whole-in-one for more information.
Index ¶
- Variables
- func CompressWriter(w io.Writer, codec string) io.Writer
- func Exec(args []string)
- func IsExecutable(path string) (ok bool, err error)
- func ListSubcommands() (cmds []string, err error)
- func LookupExecutables(pattern string) (paths []string, err error)
- func Register(name string, cmd Command)
- func SetEnv(path string)
- func Unpack(dest string, data io.Reader, codec string)
- func WriteMainGo(name, version string) error
- func WritePackGo(data []byte, codec string) error
- func WritePackingList(name string) error
- type Command
- type FuncCommand
Constants ¶
This section is empty.
Variables ¶
var HelpCommand = FuncCommand(func(_ string, _ []string) { cmds, err := ListSubcommands() if err != nil { panic(err) } fmt.Printf("usage: %s SUBCOMMAND [ARGS...]\n\n", Name) fmt.Println("Available subcommands:") for _, c := range cmds { fmt.Printf(" %s\n", c) } })
HelpCommand is a predefined built-in subcommand, which shows the default help message.
var Name = ""
Name holds the name of root command. This value is used for vriety of purposes. For example, it is used to make messages output by built-in help and version subcommand, to look up executables for subcommands, and also to determine the name of cache directory.
You can overwrite the value to customize the behavior of WIO. For example:
func init(){ wio.Name = "newname" }
Note that you must set Name in init() function, since wio has alreay created cache directory and done preparation stuffs before main() function is called.
var Version = "0"
Version holds version string of your command. Its default value is `"0"`. This is used in built-in `version` subcommand and also used to determine the name of cache directory.
As well as Name variable, you must set Version in init() function, before main() is called.
var VersionCommand = FuncCommand(func(_ string, _ []string) { fmt.Printf("%s version %s\n", Name, Version) })
VersionCommand is a predefined built-in subcommand, which shows the name and the version number of the command.
Functions ¶
func CompressWriter ¶
CompressWriter compresses w using codec.
func Exec ¶
func Exec(args []string)
Exec searches a command implementation corresponding to the name of subcommand and executes it. Because it may call exec systemcall, lines following Exec will never be executed:
func main(){ wio.Exec(os.Args[1:]) // This may call exec systemcall inside, fmt.Println("???") // thus, execution never reaches here. }
This rule is also the case for built-in commands. Exec calls os.Exit(0) when a built-in command is successfully finished. If you want to return status code from your built-in command, you need to call os.Exit with non-zero integer manually.
func IsExecutable ¶
IsExecutable reports whether the file indicated by path is an executable in a platform-dependent manner.
func ListSubcommands ¶
ListSubcommands returns names of all available subcommands in sorted order. It is handy to implement your customized help message.
func LookupExecutables ¶
LookupExecutables searches all executables matching pattern in your PATH environment variable, and returns absolute file paths of the executables. pattern is interpreted as file glob. See path/filepath#Glob for details of file glob syntax.
func Register ¶
Register binds cmd to name as a built-in subcommand. For example, if you register as follows:
wio.Register("foo", wio.FuncCommand(func(argv0 string, argv []string){ fmt.Printf("You called '%s' subcommand with: %v", argv0, argv) }))
Then, you can invoke this function in your command line like this:
$ yourcmd foo bar baz You called 'foo' subcommand with: [bar baz]
func SetEnv ¶
func SetEnv(path string)
SetEnv is called in by pack.go during preparation of environment. You should not call this.
func WriteMainGo ¶
WriteMainGo is called by wio command to generate main.go. You don't need to use this unless you want to implement your own generator.
func WritePackGo ¶
WritePackGo is called by wio command to generate pack.go. You don't need to use this unless you want to implement your own generator.
func WritePackingList ¶
WritePackingList is called by wio command to generate pack.go. You don't need to use this unless you want to implement your own generator.
Types ¶
type Command ¶
The Command type represents a built-in subcommand, which can be registered with Register function.
type FuncCommand ¶
The FuncCommand type is an adapter to allow the use of ordinary functions as built-in subcommand. If f is a function with the appropriate signature, FuncCommand(f) is a Command that calls f.
func (FuncCommand) Exec ¶
func (f FuncCommand) Exec(subname string, args []string)
Exec calls f(subname, args).