# README
CLI Core
- A library for feature-rich, configurable, and cross-project consistent command line interfaces.
Usage
- To use clicore, just define a
CommandConfig
and callconfig.Run()
.
Example
- Sample
main
package, importing your cli:
package main
import (
"myrepo/pkg/mycli"
)
func main() {
mycli.MyCommandConfig.Run()
}
- Sample package, defining your CLI library and exporting the
CommandConfig
:
package mycli
import "github.com/solo-io/go-utils/clicore"
var MyCommandConfig = clicore.CommandConfig{
Command: App,
Version: version.Version,
FileLogPathElements: FileLogPathElements,
OutputModeEnvVar: OutputModeEnvVar,
RootErrorMessage: ErrorMessagePreamble,
LoggingContext: []interface{}{"version", version.Version},
}
How to write logs to the console and log file
There are three helpers that you can use:
contextutils.CliLogInfow(ctx, "this info log goes to file and console")
contextutils.CliLogWarnw(ctx, "this warn log goes to file and console")
contextutils.CliLogErrorw(ctx, "this error log goes to file and console")
Key-value pairs are supported too:
contextutils.CliLogInfow(ctx, "this infow log should go to file and console",
"extrakey1", "val1")
Which is equivalent to the longer form:
contextutils.LoggerFrom(ctx).Infow("message going to file only",
zap.String("cli", "info that will go to the console and file",
"extrakey1", "val1")
Usage in tests
clicore
was designed to simplify CLI specification and testing.- To run
clicore
in test mode, callcliOutput, err := cli.GlooshotConfig.RunForTest(args)
.- Output from the command (stdout, stderr, and any log files) can then be validated one by one.
- See the test file for an example
# Packages
No description provided by the author
# Functions
BuildCliLogger creates a set of loggers for use in CLI applications.
BuildMockedCliLogger is the test-environment counterpart of BuildCliLogger It stores log output in buffers that can be inspected by tests.
ExecuteCliOutErr is a helper for calling a cobra command within a test.
FilePathFromHomeDir is a utility that makes it easier to find the absolute path to a file, given its file path elements relative to its home directory.
No description provided by the author
No description provided by the author
# Structs
CliOutput captures all the relevant output from a Cobra Command For clarity and simplicity, output from zapcore loggers are stored separately otherwise, it would be necessary to coordinate the initialization of the loggers with the os.Std*** manipulation done in ExecuteCliOutErr.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author