coreutils

package
v2.19.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 22 Imported by: 53

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (

	// General core constants
	OnErrorPanic OnError = "panic"

	// Common
	TokenRefreshDisabled        = 0
	TokenRefreshDefaultInterval = 60

	// Home Dir
	JfrogCertsDirName                   = "certs"
	JfrogConfigFile                     = "jfrog-cli.conf"
	JfrogDependenciesDirName            = "dependencies"
	JfrogSecurityDirName                = "security"
	JfrogSecurityConfFile               = "security.yaml"
	JfrogBackupDirName                  = "backup"
	JfrogLogsDirName                    = "logs"
	JfrogLocksDirName                   = "locks"
	JfrogPluginsDirName                 = "plugins"
	PluginsExecDirName                  = "bin"
	PluginsResourcesDirName             = "resources"
	JfrogPluginsFileName                = "plugins.yml"
	JfrogTransferDirName                = "transfer"
	JfrogTransferStateFileName          = "state.json"
	JfrogTransferErrorsDirName          = "errors"
	JfrogTransferRetryableErrorsDirName = "retryable"
	JfrogTransferSkippedErrorsDirName   = "skipped"

	// Env
	ErrorHandling      = "JFROG_CLI_ERROR_HANDLING"
	TempDir            = "JFROG_CLI_TEMP_DIR"
	LogLevel           = "JFROG_CLI_LOG_LEVEL"
	LogTimestamp       = "JFROG_CLI_LOG_TIMESTAMP"
	ReportUsage        = "JFROG_CLI_REPORT_USAGE"
	DependenciesDir    = "JFROG_CLI_DEPENDENCIES_DIR"
	TransitiveDownload = "JFROG_CLI_TRANSITIVE_DOWNLOAD_EXPERIMENTAL"
	CI                 = "CI"
)
View Source
const (
	Maven  = "Maven"
	Gradle = "Gradle"
	Npm    = "npm"
	Yarn   = "Yarn"
	Go     = "go"
	Pip    = "pip"
	Pipenv = "pipenv"
	Nuget  = "nuget"
	Dotnet = "dotnet"
	Docker = "docker"
)
View Source
const (
	GettingStartedGuideUrl = "https://github.com/jfrog/jfrog-cli/blob/v2/guides/getting-started-with-jfrog-using-the-cli.md"
)

Variables ΒΆ

View Source
var (
	HomeDir     = "JFROG_CLI_HOME_DIR"
	BuildName   = "JFROG_CLI_BUILD_NAME"
	BuildNumber = "JFROG_CLI_BUILD_NUMBER"
	Project     = "JFROG_CLI_BUILD_PROJECT"
)

Although these vars are constant, they are defined inside a vars section and not a constants section because the tests modify these values.

View Source
var DefaultMaxColWidth = 25

Controls the max col width when printing to a non-terminal. See the PrintTable description for more info.

View Source
var ExitCodeError = ExitCode{1}
View Source
var ExitCodeFailNoOp = ExitCode{2}
View Source
var ExitCodeNoError = ExitCode{0}
View Source
var ExitCodeVulnerableBuild = ExitCode{3}

Functions ΒΆ

func AskYesNo ΒΆ

func AskYesNo(promptPrefix string, defaultValue bool) bool

Ask a yes or no question, with a default answer.

func ChmodPluginsDirectoryContent ΒΆ added in v2.13.0

func ChmodPluginsDirectoryContent() error

func Contains ΒΆ added in v2.17.0

func Contains(arr []string, str string) bool

func ConvertExitCodeError ΒΆ added in v2.1.0

func ConvertExitCodeError(err error) error

When running a command in an external process, if the command fails to run or doesn't complete successfully ExitError is returned. We would like to return a regular error instead of ExitError, because some frameworks (such as codegangsta used by JFrog CLI) automatically exit when this error is returned.

func CreateDirInJfrogHome ΒΆ

func CreateDirInJfrogHome(dirName string) (string, error)

func DetectTechnologies ΒΆ added in v2.7.0

func DetectTechnologies(path string, isCiSetup, recursive bool) (map[Technology]bool, error)

DetectTechnologies tries to detect all technologies types according to the files in the given path. 'isCiSetup' will limit the search of possible techs to Maven, Gradle, and npm. 'recursive' will determine if the search will be limited to files in the root path or not.

func DetectedTechnologiesToSlice ΒΆ added in v2.12.0

func DetectedTechnologiesToSlice(detected map[Technology]bool) []string

DetectedTechnologiesToSlice returns a string slice that includes all the names of the detected technologies.

func DetectedTechnologiesToString ΒΆ added in v2.10.0

func DetectedTechnologiesToString(detected map[Technology]bool) string

DetectTechnologiesToString returns a string that includes all the names of the detected technologies separated by a comma.

func ExitOnErr ΒΆ

func ExitOnErr(err error)

func ExtractDetailedSummaryFromArgs ΒΆ

func ExtractDetailedSummaryFromArgs(args []string) (cleanArgs []string, detailedSummary bool, err error)

func ExtractFailFromArgs ΒΆ added in v2.10.0

func ExtractFailFromArgs(args []string) (cleanArgs []string, fail bool, err error)

Used by docker

func ExtractInsecureTlsFromArgs ΒΆ

func ExtractInsecureTlsFromArgs(args []string) (cleanArgs []string, insecureTls bool, err error)

func ExtractLicensesFromArgs ΒΆ added in v2.10.0

func ExtractLicensesFromArgs(args []string) (cleanArgs []string, licenses bool, err error)

Used by docker scan (Xray)

func ExtractRepoPathFromArgs ΒΆ added in v2.10.0

func ExtractRepoPathFromArgs(args []string) (cleanArgs []string, repoPath string, err error)

Used by docker scan (Xray)

func ExtractServerIdFromCommand ΒΆ added in v2.10.0

func ExtractServerIdFromCommand(args []string) (cleanArgs []string, serverId string, err error)

func ExtractSkipLoginFromArgs ΒΆ added in v2.10.0

func ExtractSkipLoginFromArgs(args []string) (cleanArgs []string, skipLogin bool, err error)

Used by docker

func ExtractThreadsFromArgs ΒΆ added in v2.10.0

func ExtractThreadsFromArgs(args []string, defaultValue int) (cleanArgs []string, threads int, err error)

func ExtractWatchesFromArgs ΒΆ added in v2.10.0

func ExtractWatchesFromArgs(args []string) (cleanArgs []string, watches string, err error)

Used by docker scan (Xray)

func ExtractXrayOutputFormatFromArgs ΒΆ added in v2.4.1

func ExtractXrayOutputFormatFromArgs(args []string) (cleanArgs []string, format string, err error)

func ExtractXrayScanFromArgs ΒΆ

func ExtractXrayScanFromArgs(args []string) (cleanArgs []string, xrayScan bool, err error)

func FindBooleanFlag ΒΆ

func FindBooleanFlag(flagName string, args []string) (flagIndex int, flagValue bool, err error)

Boolean flag can be provided in one of the following forms: 1. --flag=value, where value can be true/false 2. --flag, here the value is true Return values: flagIndex - index of flagName in args. flagValue - value of flagName. err - error if flag exists, but we failed to extract its value. If flag does not exist flagIndex = -1 with false value and nil error.

func FindFlag ΒΆ

func FindFlag(flagName string, args []string) (flagIndex, flagValueIndex int, flagValue string, err error)

Find value of required CLI flag in Command. If flag does not exist, the returned index is -1 and nil is returned as the error. Return values: err - error if flag exists but failed to extract its value. flagIndex - index of flagName in Command. flagValueIndex - index in Command in which the value of the flag exists. flagValue - value of flagName.

func FindFlagFirstMatch ΒΆ

func FindFlagFirstMatch(flags, args []string) (flagIndex, flagValueIndex int, flagValue string, err error)

Find the first match of the provided flags in args. Return same values as FindFlag.

func GetAllTechnologiesList ΒΆ added in v2.18.7

func GetAllTechnologiesList() (technologies []string)

func GetCliConfigVersion ΒΆ added in v2.13.0

func GetCliConfigVersion() int

GetCliConfigVersion returns the latest version of the config.yml file on the file system at '.jfrog'.

func GetCliExecutableName ΒΆ added in v2.5.0

func GetCliExecutableName() string

func GetCliPersistentTempDirPath ΒΆ

func GetCliPersistentTempDirPath() string

Return the path of CLI temp dir. This path should be persistent, meaning - should not be cleared at the end of a CLI run.

func GetCliUserAgent ΒΆ

func GetCliUserAgent() string

func GetCliUserAgentName ΒΆ

func GetCliUserAgentName() string

func GetCliUserAgentVersion ΒΆ

func GetCliUserAgentVersion() string

func GetClientAgentName ΒΆ

func GetClientAgentName() string

func GetClientAgentVersion ΒΆ

func GetClientAgentVersion() string

func GetJfrogBackupDir ΒΆ

func GetJfrogBackupDir() (string, error)

func GetJfrogCertsDir ΒΆ

func GetJfrogCertsDir() (string, error)

func GetJfrogConfigLockDir ΒΆ added in v2.2.0

func GetJfrogConfigLockDir() (string, error)

func GetJfrogHomeDir ΒΆ

func GetJfrogHomeDir() (string, error)

func GetJfrogLocksDir ΒΆ added in v2.2.0

func GetJfrogLocksDir() (string, error)

func GetJfrogPluginsDir ΒΆ

func GetJfrogPluginsDir() (string, error)

func GetJfrogPluginsLockDir ΒΆ added in v2.13.0

func GetJfrogPluginsLockDir() (string, error)

func GetJfrogPluginsResourcesDir ΒΆ added in v2.13.0

func GetJfrogPluginsResourcesDir(pluginsName string) (string, error)

func GetJfrogSecurityConfFilePath ΒΆ

func GetJfrogSecurityConfFilePath() (string, error)

func GetJfrogSecurityDir ΒΆ

func GetJfrogSecurityDir() (string, error)

func GetJfrogTransferDir ΒΆ added in v2.17.0

func GetJfrogTransferDir() (string, error)

func GetJfrogTransferErrorsDir ΒΆ added in v2.17.0

func GetJfrogTransferErrorsDir() (string, error)

func GetJfrogTransferRetryableDir ΒΆ added in v2.17.0

func GetJfrogTransferRetryableDir() (string, error)

func GetJfrogTransferSkippedDir ΒΆ added in v2.17.0

func GetJfrogTransferSkippedDir() (string, error)

func GetJfrogTransferStateFilePath ΒΆ added in v2.17.0

func GetJfrogTransferStateFilePath() (string, error)

func GetPluginsConfigVersion ΒΆ added in v2.13.0

func GetPluginsConfigVersion() int

GetPluginsConfigVersion returns the latest plugins layout version on the file system (at '.jfrog/plugins').

func GetPluginsDirContent ΒΆ added in v2.13.0

func GetPluginsDirContent() ([]os.DirEntry, error)

func GetTechnologyPackageDescriptor ΒΆ added in v2.19.0

func GetTechnologyPackageDescriptor(tech string) string

func GetTechnologyPackageType ΒΆ added in v2.9.0

func GetTechnologyPackageType(techName Technology) string

func GetWorkingDirectory ΒΆ

func GetWorkingDirectory() (string, error)

func IsAnyEmpty ΒΆ

func IsAnyEmpty(strings ...string) bool

func IsLinux ΒΆ

func IsLinux() bool

func IsWindows ΒΆ

func IsWindows() bool

func ListToText ΒΆ added in v2.11.3

func ListToText(list []string) string

Turn a list of strings into a sentence. For example, turn ["one", "two", "three"] into "one, two and three". For a single element: "one".

func PanicOnError ΒΆ

func PanicOnError(err error) error

func PrepareTable ΒΆ added in v2.11.3

func PrepareTable(rows interface{}, emptyTableMessage string, printExtended bool) (table.Writer, error)

Creates table following the logic described in PrintTable. Returns: Table Writer (table.Writer) - Can be used to adjust style, output mirror, render type, etc. Error if occurred.

func PrintBold ΒΆ added in v2.7.2

func PrintBold(str string) string

Print the test to the console with bold style.

func PrintComment ΒΆ added in v2.7.2

func PrintComment(str string) string

Print the test to the console in gray color.

func PrintLink(str string) string

Print the test to the console in cyan color.

func PrintMessage ΒΆ added in v2.1.0

func PrintMessage(message string)

PrintMessage prints message in a frame (which is actually a table with a single table). For example: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ An example of a message in a nice frame β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

func PrintTable ΒΆ added in v2.1.0

func PrintTable(rows interface{}, title string, emptyTableMessage string, printExtended bool) (err error)

PrintTable prints a slice of rows in a table. The parameter rows MUST be a slice, otherwise the method panics. How to use this method (with an example): The fields of the struct must have one of the tags: 'col-name' or 'embed-table' in order to be printed. Fields without any of these tags will be skipped. The tag 'col-name' can be set on string fields only. The column name is the 'col-name' tag value. On terminal, the maximum column width is calculated (terminal width equally divided between columns), while on non-terminal the value of the DefaultMaxColWidth variable is used. If the cell content exceeds the defined max column width, the content will be broken into two (or more) lines. In case the struct you want to print contains a field that is a slice of other structs, you can print it in the table too with the 'embed-table' tag which can be set on slices of structs only. Fields with the 'extended' tag will be printed iff the 'printExtended' bool input is true.

Example: These are the structs Customer and Product:

type Customer struct {
    name     string    `col-name:"Name"`
    age      string    `col-name:"Age"`
    products []Product `embed-table:"true"`
}
type Product struct {
    title string `col-name:"Product Title"`
    CatNumber string `col-name:"Product\nCatalog #"`
    Color string `col-name:"Color" extended:"true"`
}

We'll use it, and run these commands (var DefaultMaxColWidth = 25):

customersSlice := []Customer{
    {name: "Gai", age: "350", products: []Product{{title: "SpiderFrog Shirt - Medium", CatNumber: "123456", Color: "Green"}, {title: "Floral Bottle", CatNumber: "147585", Color: "Blue"}}},
    {name: "Noah", age: "21", products: []Product{{title: "Pouch", CatNumber: "456789", Color: "Red"}, {title: "Ching Ching", CatNumber: "963852", Color: "Gold"}}},
}

err := coreutils.PrintTable(customersSlice, "Customers", "No customers were found", false)

That's the table printed:

Customers β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ NAME β”‚ AGE β”‚ PRODUCT TITLE β”‚ PRODUCT β”‚ β”‚ β”‚ β”‚ β”‚ CATALOG # β”‚ β”œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Gai β”‚ 350 β”‚ SpiderFrog Shirt - Medi β”‚ 123456 β”‚ β”‚ β”‚ β”‚ um β”‚ β”‚ β”‚ β”‚ β”‚ Floral Bottle β”‚ 147585 β”‚ β”œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Noah β”‚ 21 β”‚ Pouch β”‚ 456789 β”‚ β”‚ β”‚ β”‚ Ching Ching β”‚ 963852 β”‚ β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

If printExtended=true:

err := coreutils.PrintTable(customersSlice, "Customers", "No customers were found", true)

Customers β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ NAME β”‚ AGE β”‚ PRODUCT TITLE β”‚ PRODUCT β”‚ Color β”‚ β”‚ β”‚ β”‚ β”‚ CATALOG # β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Gai β”‚ 350 β”‚ SpiderFrog Shirt - Medi β”‚ 123456 β”‚ Green β”‚ β”‚ β”‚ β”‚ um β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Floral Bottle β”‚ 147585 β”‚ Blue β”‚ β”œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Noah β”‚ 21 β”‚ Pouch β”‚ 456789 β”‚ Red β”‚ β”‚ β”‚ β”‚ Ching Ching β”‚ 963852 β”‚ Gold β”‚ β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

If customersSlice was empty, emptyTableMessage would have been printed instead:

Customers β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ No customers were found β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

func PrintTitle ΒΆ added in v2.7.2

func PrintTitle(str string) string

Print the test to the console in green color.

func RemoveAllWhiteSpaces ΒΆ added in v2.11.3

func RemoveAllWhiteSpaces(input string) string

func RemoveFlagFromCommand ΒΆ

func RemoveFlagFromCommand(args *[]string, flagIndex, flagValueIndex int)

Removes the provided flag and value from the command arguments

func ReplaceVars ΒΆ

func ReplaceVars(content []byte, specVars map[string]string) []byte

func SetCliExecutableName ΒΆ added in v2.5.0

func SetCliExecutableName(executableName string)

func SetCliUserAgentName ΒΆ

func SetCliUserAgentName(cliUserAgentNameToSet string)

func SetCliUserAgentVersion ΒΆ

func SetCliUserAgentVersion(versionToSet string)

func SetClientAgentName ΒΆ

func SetClientAgentName(clientAgentToSet string)

func SetClientAgentVersion ΒΆ

func SetClientAgentVersion(versionToSet string)

func SetIfEmpty ΒΆ

func SetIfEmpty(str *string, defaultStr string) bool

func SpecVarsStringToMap ΒΆ

func SpecVarsStringToMap(rawVars string) map[string]string

func SumTrueValues ΒΆ

func SumTrueValues(boolArr []bool) int

Types ΒΆ

type CliError ΒΆ

type CliError struct {
	ExitCode
	ErrorMsg string
}

func (CliError) Error ΒΆ

func (err CliError) Error() string

type Credentials ΒΆ

type Credentials interface {
	SetUser(string)
	SetPassword(string)
	GetUser() string
	GetPassword() string
}

type ExitCode ΒΆ

type ExitCode struct {
	Code int
}

Exit codes:

func GetExitCode ΒΆ

func GetExitCode(err error, success, failed int, failNoOp bool) ExitCode

type GeneralExecCmd ΒΆ

type GeneralExecCmd struct {
	ExecPath string
	Command  []string
}

Command used to execute general commands.

func (*GeneralExecCmd) GetCmd ΒΆ

func (pluginCmd *GeneralExecCmd) GetCmd() *exec.Cmd

func (*GeneralExecCmd) GetEnv ΒΆ

func (pluginCmd *GeneralExecCmd) GetEnv() map[string]string

func (*GeneralExecCmd) GetErrWriter ΒΆ

func (pluginCmd *GeneralExecCmd) GetErrWriter() io.WriteCloser

func (*GeneralExecCmd) GetStdWriter ΒΆ

func (pluginCmd *GeneralExecCmd) GetStdWriter() io.WriteCloser

type OnError ΒΆ

type OnError string

Error modes (how should the application behave when the CheckError function is invoked):

type TechData ΒΆ added in v2.9.0

type TechData struct {
	// The name of the package type used in this technology.
	PackageType string
	// contains filtered or unexported fields
}

type Technology ΒΆ added in v2.7.0

type Technology string

func ToTechnologies ΒΆ added in v2.12.0

func ToTechnologies(args []string) (technologies []Technology)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher πŸ‡»πŸ‡³