cmd

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	TEST_PATH   = "test_path"
	OUTPUT_TYPE = "output"
	REPORT_PATH = "report_path"
	VERBOSE     = "verbose"
	RACE        = "race"
)

flag names

View Source
const (
	DEFAULT_TEST_PATH   = "./..."
	DEFAULT_OUTPUT_TYPE = string(CLI)
	DEFAULT_REPORT_PATH = "./report"
	DEFAULT_VERBOSE     = false
	DEFAULT_RACE        = false
)

DEFAULT_XXX is used for default values of flags

View Source
const (
	RLT_PASS    result = "PASS"
	RLT_FAIL    result = "FAIL"
	RLT_SKIP    result = "SKIP"
	RLT_UNKNOWN result = "Unknown" // could be set if test is terminated for some reason before executing it
)
View Source
const (
	START  action = "start"
	RUN    action = "run"
	PAUSE  action = "pause"
	CONT   action = "cont"
	PASS   action = "pass"
	BENCH  action = "bench"
	FAIL   action = "fail"
	OUTPUT action = "output"
	SKIP   action = "skip" // NOTE: it is set if no tests in a package
)
View Source
const (
	RECURSIVE_SUFFIX = "/..."
)

Variables

View Source
var InternalFS fs.FS

InternalFS is a global variable shared within the whole cmd package. It is set in the `Execute()` when main function run because go embed cannot access parent directory.

View Source
var SeverityRegex = regexp.MustCompile(fmt.Sprintf(`%s(\w+)`, test.SEVERITY_LOG_PREFIX))
View Source
var TestCmd = &cobra.Command{
	Use:   "test [test path]",
	Short: "Run tests and generate the result report",
	Long: `Run tests with go test command and generate a report by specifying a path under which to run tests (default "./...")
You also have several options for output type, report path and verbose output`,
	Args:         cobra.MaximumNArgs(1),
	RunE:         runTest,
	SilenceUsage: true,
}

TestCmd represents the test command

Functions

func Execute

func Execute(internalFS fs.FS)

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FirstLower added in v2.0.9

func FirstLower(s string) string

func FirstUpper added in v2.0.9

func FirstUpper(s string) string

func NewGenerator added in v2.0.9

func NewGenerator(pkgName string, source string, destination string, specMap map[string]map[string]spec) *generator

Types

type Command

type Command struct {
	ProjectObject Project
	CommandName   string
}

type DockerComposefile

type DockerComposefile struct {
	ProjectObject Project
	AppPort       int
}

type Dockerfile

type Dockerfile struct {
	ProjectObject Project
	GoVersion     string
	AppPort       int
}

type Handler

type Handler struct {
	ProjectObject    Project
	HandlerNameUpper string
	HandlerNameLower string
	ServiceExists    bool
}

type OutputType

type OutputType string

OutputType is a type of output of test results

const (
	CLI  OutputType = "cli"
	JSON OutputType = "json"
	HTML OutputType = "html"
)

type Project

type Project struct {
	// Copyright is the copyright text on the top of every files.
	Copyright string
	// PkgPath is the full string of the generated package. (example: github.com/retail-ai-inc/bean/v2)
	PkgPath string
	// PkgName is the suffix of the package path, it should match the current directory name.
	PkgName string
	// RootDir is the project root directory or current directory when executing the bean command.
	RootDir string
	// SubDir is the sub directory under project root using for some commands. (example: upgrade need ./framework)
	SubDir string
	// RootFS contains the internal FS directory which need to be walk through recursively,
	// different cmd may starts with different root path.(init: internal/project, upgrade: internal/project/framework).
	RootFS fs.FS
	// Secret is similar like a passphrase to hold a key to generate tokens, hash password or similar security credentials.
	Secret string
	// JWT secret/salt
	JWTSecret string
	// API Authorization: bearer token to delete a key from Memory database via API call.
	BearerToken string
}

Project holds some necessary data for some cmd.

type Repo

type Repo struct {
	ProjectObject Project
	RepoNameUpper string
	RepoNameLower string
}

type Service

type Service struct {
	ProjectObject    Project
	ServiceNameUpper string
	ServiceNameLower string
	RepoExists       bool
}

Directories

Path Synopsis
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

Jump to

Keyboard shortcuts

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