command

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package command provides interfaces for the shell commands and programs on the host.

Index

Constants

View Source
const (
	Arc      = "arc"      // Arc is the arc decompression command.
	Arj      = "arj"      // Arj is the arj decompression command.
	Ansilove = "ansilove" // Ansilove is the ansilove text to image command.
	Convert  = "convert"  // Convert is the ImageMagick convert command.
	Cwebp    = "cwebp"    // Cwebp is the Google create webp command.
	Gwebp    = "gif2webp" // Gwebp is the Google gif to webp command.
	Optipng  = "optipng"  // Optipng is the PNG optimizer command.
	P7zip    = "7z"       // P7zip is the 7-Zip decompression command.
	Tar      = "tar"      // Tar is the tar decompression command.
	// A note about unrar on linux, the installation cannot use the unrar-free package,
	// which is a poor substitute for the files this application needs to handle.
	// The unrar binary should return:
	// "UNRAR 6.24 freeware, Copyright (c) 1993-2023 Alexander Roshal".
	Unrar = "unrar" // Unrar is the rar decompression command.
	Unzip = "unzip" // Unzip is the zip decompression command.
)

Variables

View Source
var (
	ErrEmpty = errors.New("file is empty")
	ErrImg   = errors.New("file is not an known image format")
	ErrIsDir = errors.New("file is a directory")
	ErrMatch = errors.New("no match value is present")
	ErrVers  = errors.New("version mismatch")
	ErrZap   = errors.New("zap logger instance is nil")
)

Functions

func ArjExitStatus

func ArjExitStatus(err error) string

ArjExitStatus returns the exit status of the arj command error.

func BaseName

func BaseName(path string) string

BaseName returns the base name of the file without the extension. Both the directory and extension are removed.

func BaseNamePath

func BaseNamePath(path string) string

BaseNamePath returns the directory and base name of the file without the extension.

func CopyFile

func CopyFile(logger *zap.SugaredLogger, src, dst string) error

CopyFile copies the src file to the dst file and path.

func ExtractOne

func ExtractOne(logger *zap.SugaredLogger, src, dst, extHint, name string) error

ExtractOne extracts the named file from the src archive.

The extracted file is copied to the dst. It uses exec.Command and relies on extractor being available on the system host path. Using non-Go apps allows for better compatibility with retro zip archives, such as those that use the compression methods prior to zip deflate.

The src argument is the path to the zip archive. The dst argument is the destination filepath and should end with a file extension, eg. ".txt". The optional extHint arg is a file extension hint for the extractor. Valid hints are: ".arc", ".arj", ".rar", ".tar", ".zip", otherwise the extractor will use the 7-Zip command. The name argument is the name of the one file to unzip and copy.

func Infos

func Infos() []string

Infos returns details for the list of the execute command names used by the application.

func LookCmd

func LookCmd(name string) error

LookCmd returns an error if the named command is not found in the system path.

func LookVersion

func LookVersion(name, flag, match string) error

LookVersion returns an error when the match string is not found in the named command output.

func LookupUnrar

func LookupUnrar() error

LookupUnrar returns an error if the name Alexander Roshal is not found in the unrar version output.

func Lookups

func Lookups() []string

Lookups returns a list of the execute command names used by the application.

func OptimizePNG

func OptimizePNG(src string) error

OptimizePNG optimizes the src PNG image using the optipng command. The optimization is done in-place, overwriting the src file. It should be used in a deferred function.

func RemoveImgs

func RemoveImgs(unid string, dirs ...string) error

RemoveImgs removes unid named images with .jpg, .png and .webp extensions from the directory paths. A nil is returned if the directory or the named unid files do not exist.

func RemoveMe

func RemoveMe(unid, dir string) error

RemoveMe removes the file with the unid name combined with a ".txt" extension from the download directory path. It returns nil if the file does not exist.

func Run

func Run(logger *zap.SugaredLogger, name string, arg ...string) error

Run looks for the command in the system path and executes it with the arguments. Any output to stderr is logged as a debug message.

func RunOut

func RunOut(name string, arg ...string) ([]byte, error)

RunOut looks for the command in the system path and executes it with the arguments. Any output is sent to the stdout buffer.

func RunQuiet

func RunQuiet(name string, arg ...string) error

RunQuiet looks for the command in the system path and executes it with the arguments.

func RunWD

func RunWD(logger *zap.SugaredLogger, name, wdir string, arg ...string) error

RunWD looks for the command in the system path and executes it with the arguments. An optional working directory is set for the command. Any output to stderr is logged as a debug message.

func UnRarExitStatus

func UnRarExitStatus(err error) string

UnRarExitStatus returns the exit status of the unrar command error.

Types

type Args

type Args []string

Args is a slice of strings that represents the command line arguments. Each argument and its value is a separate string in the slice.

func (*Args) AnsiAmiga

func (a *Args) AnsiAmiga()

AnsiDOS appends the command line arguments for the ansilove command to transform an Commodore Amiga ANSI text file into a PNG image.

func (*Args) AnsiDOS

func (a *Args) AnsiDOS()

AnsiDOS appends the command line arguments for the ansilove command to transform an ANSI text file into a PNG image.

func (*Args) CWebp

func (a *Args) CWebp()

CWebp appends the command line arguments for the cwebp command to transform an image into a webp image.

func (*Args) GWebp

func (a *Args) GWebp()

GWebp appends the command line arguments for the gif2webp command to transform a GIF image into a webp image.

func (*Args) Jpeg

func (a *Args) Jpeg()

Jpeg appends the command line arguments for the convert command to transform an image into a JPEG image.

func (*Args) Png

func (a *Args) Png()

Png appends the command line arguments for the convert command to transform an image into a PNG image.

func (*Args) Thumb

func (a *Args) Thumb()

Thumb appends the command line arguments for the convert command to transform an image into a thumbnail image.

type Dirs

type Dirs struct {
	Download  string // Download is the directory path for the file downloads.
	Preview   string // Preview is the directory path for the image previews.
	Thumbnail string // Thumbnail is the directory path for the image thumbnails.
}

Dirs is a struct of the download, preview and thumbnail directories.

func (Dirs) AnsiLove

func (dir Dirs) AnsiLove(logger *zap.SugaredLogger, src, unid string) error

AnsiLove converts the src text file and creates a PNG image in the preview directory. A webp thumbnail image is also created and copied to the thumbnail directory.

func (Dirs) AnsiThumbnail

func (dir Dirs) AnsiThumbnail(src, unid string) error

AnsiThumbnail converts the src image to a 400x400 pixel, webp image in the thumbnail directory. The conversion is done using a temporary, lossless PNG image.

func (Dirs) ExtractAnsiLove

func (dir Dirs) ExtractAnsiLove(logger *zap.SugaredLogger, src, extHint, unid, name string) error

ExtractAnsiLove extracts the named text file from a zip archive. The text file is converted to a PNG preview and a webp thumbnails. Any text file usable by the ansilove command is supported, including ANSI, codepage plain text, PCBoard, etc.

func (Dirs) ExtractImage

func (dir Dirs) ExtractImage(logger *zap.SugaredLogger, src, extHint, unid, name string) error

ExtractImage extracts the named image file from a zip archive. Based on the file extension, the image is converted to a webp preview and thumbnails. Named files with a PNG extension are optimized but kept as the preview image.

func (Dirs) LosslessScreenshot

func (dir Dirs) LosslessScreenshot(logger *zap.SugaredLogger, src, unid string) error

LosslessScreenshot converts the src image to a lossless PNG image in the screenshot directory. A webp thumbnail image is also created and copied to the thumbnail directory. The lossless conversion is useful for screenshots of text, terminals interfaces and pixel art.

The lossless conversion is done using the ImageMagick convert command.

func (Dirs) PreviewGIF

func (dir Dirs) PreviewGIF(logger *zap.SugaredLogger, src, unid string) error

PreviewPNG copies and optimizes the src PNG image to the screenshot directory. A webp thumbnail image is also created and copied to the thumbnail directory.

func (Dirs) PreviewLossy

func (dir Dirs) PreviewLossy(logger *zap.SugaredLogger, src, unid string) error

PreviewLossy converts the src image to a lossy Webp image in the screenshot directory. A webp thumbnail image is also created and copied to the thumbnail directory. The lossy conversion is useful for photographs.

The lossy conversion is done using the ImageMagick convert command.

func (Dirs) PreviewPNG

func (dir Dirs) PreviewPNG(logger *zap.SugaredLogger, src, unid string) error

PreviewPNG copies and optimizes the src PNG image to the screenshot directory. A webp thumbnail image is also created and copied to the thumbnail directory.

func (Dirs) PreviewWebP

func (dir Dirs) PreviewWebP(logger *zap.SugaredLogger, src, unid string) error

PreviewWebP converts the src image to a webp image in the screenshot directory. A webp thumbnail image is also created and copied to the thumbnail directory.

The conversion is done using the cwebp command, which supports either a PNG, JPEG, TIFF or WebP source image file.

func (Dirs) WebpThumbnail

func (dir Dirs) WebpThumbnail(src, unid string) error

WebpThumbnail converts the src image to a 400x400 pixel, webp image in the thumbnail directory. The conversion is done using a temporary, lossy PNG image.

Jump to

Keyboard shortcuts

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