cmdutil

package
v0.0.0-...-96c42fd Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationFlagDocker         = "flag-docker"
	AnnotationFlagInteractive    = "flag-interactive"
	AnnotationFlagFileConstrains = "flag-file-validations"
	AnnotationFlagFileOutput     = "flag-file-output"

	FlagDocker         = "docker"
	FlagDaemon         = "daemon"
	FlagInteractive    = "interactive"
	FlagFileConstrains = "ignore-file-validations"
	FlagValidations    = "ignore-validations"
	FlagFileOutput     = "output"

	// Path annotations should check against the given cmd exists in $PATH, else
	// throw an error.
	PathFfmpeg  = "ffmpeg"
	PathFfprobe = "ffprobe"
)

Variables

View Source
var (
	ErrorMultiCommandDaemon       = errors.New("cannot run command as daemon on host machine, you can use --docker with --daemon")
	ErrorInteractiveCommandDaemon = errors.New("cannot run interactive command as daemon")
)
View Source
var (
	ErrorNotVideoFile     = errors.New("file provided is not in a video format, can be suppressed with --ignore-file-validations flag")
	ErrorNotImageFile     = errors.New("file provided is not in an image format, can be suppressed with --ignore-file-validations flag")
	ErrorNotAudioFile     = errors.New("file provided is not in an audio format, can be suppressed with --ignore-file-validations flag")
	ErrorNotAcceptedFile  = errors.New("file provided is not in an acceptable format, can be suppressed with --ignore-file-validations flag")
	ErrorFileDoesNotExist = errors.New("file does not exist")
)
View Source
var (
	DockerImage  string
	DockerLabels = map[string]string{"creator": "godl"}
)

Functions

func AddGroup

func AddGroup(parent *cobra.Command, title string, cmds ...*cobra.Command)

func AudioFile

func AudioFile(f *InputFile) error

func BindInputFile

func BindInputFile(f *InputFile, path string) error

func CanonicalizePaths

func CanonicalizePaths(paths ...*string) error

CanonicalizePaths updates each path to it's full system path. Deprecated: use InputFile

func CreateFolder

func CreateFolder(path string) error

CreateFolder Checks if folder exists and if it doesn't it creates it.

func DockerfyCommand

func DockerfyCommand(cmd *cobra.Command, args []string) []string

DockerfyCommand returns a slice with all parts of the invoked command

func ImageFile

func ImageFile(f *InputFile) error

func IsFileAudio

func IsFileAudio(filepath string) (bool, error)

func IsFileAudioOrVideo

func IsFileAudioOrVideo(filepath string) (isAudio, isVideo bool, err error)

func IsFileImage

func IsFileImage(filepath string) (bool, error)

func IsFileVideo

func IsFileVideo(filepath string) (bool, error)

func PathsToMounts

func PathsToMounts(paths ...string) (mounts map[string]string)

PathsToMounts adds active directory, prepares dirs for docker volume binding

func ReadFileIntoJSON

func ReadFileIntoJSON(path string, jsonStruct any) error

func VideoFile

func VideoFile(f *InputFile) error

Types

type Factory

type Factory struct {
	Logger *zap.Logger
	// Docker wrapper a helper struct to start containers
	// Deprecated: will be removed in v5.0.0
	Docker docker.Wrapper

	// Output sets the output filename, applicable for commands with "flag-output" annotation.
	Output string
	// Interactive starts a tui, applicable for commands with "flag-interactive" annotation.
	Interactive bool
	// ExecuteInDocker run the command inside docker
	ExecuteInDocker bool
	// IgnoreValidations run the command without performing any validations
	IgnoreValidations bool
	// IgnoreFileConstrains run the command without performing any InputFile validations
	IgnoreFileConstrains bool
	// Daemon run the command in daemon. This can cause an orphaned process if the command expects any user input.
	Daemon bool
	// Debug set the Logger level to debug mode
	Debug bool
	// InsideDocker states if the command is currently running inside docker.
	InsideDocker bool
}

func NewFactory

func NewFactory(logger *zap.Logger) *Factory

func (*Factory) AddAnnotationFlags

func (f *Factory) AddAnnotationFlags(cmd *cobra.Command)

revive:disable:cognitive-complexity

func (*Factory) ListenForCancelSignals

func (f *Factory) ListenForCancelSignals(cancel context.CancelFunc)

func (*Factory) ValidateAnnotations

func (f *Factory) ValidateAnnotations(cmd *cobra.Command) error

type InputFile

type InputFile struct {
	// Name of the file including Ext
	Name string
	// BaseName name of the file without Ext
	BaseName string
	// Ext of the file including "."
	Ext string
	// Path to the file
	Path string

	IgnoreConstraints bool
	// contains filtered or unexported fields
}

func NewInputFile

func NewInputFile(constraints ...InputFileConstrains) *InputFile

func (*InputFile) Canonicalize

func (f *InputFile) Canonicalize() error

Canonicalize gets the absolute system path of the current InputFile.

func (*InputFile) IsAudio

func (f *InputFile) IsAudio() bool

IsAudio assumes the file has already been read into memory.

func (*InputFile) IsImage

func (f *InputFile) IsImage() bool

IsImage assumes the file has already been read into memory.

func (*InputFile) IsVideo

func (f *InputFile) IsVideo() bool

IsVideo assumes the file has already been read into memory.

func (*InputFile) ReadFile

func (f *InputFile) ReadFile() ([]byte, error)

func (*InputFile) Set

func (f *InputFile) Set(path string) error

Set satisfy the flag interface

func (*InputFile) String

func (f *InputFile) String() string

String satisfy the flag interface

func (*InputFile) Type

func (*InputFile) Type() string

Type satisfy the flag interface

func (*InputFile) ValidateAnd

func (f *InputFile) ValidateAnd() error

ValidateAnd checks the file against all constrains, if any of them fail, return an error

func (*InputFile) ValidateOr

func (f *InputFile) ValidateOr() error

ValidateOr checks the file until one constrain passes, if none do, return an error

type InputFileConstrains

type InputFileConstrains func(f *InputFile) error

InputFileConstrains are constrains run against the file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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