util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreChecksumsEqual

func AreChecksumsEqual(f1, f2 string) (bool, error)

AreChecksumsEqual - compare checksums for two files

func BuildRepoArchiveUrl added in v0.3.0

func BuildRepoArchiveUrl(owner, repo, branch string) string

BuildRepoArchiveURL - construct a URL pointing to a zipped Github Repo

func BuildRepoUrl added in v0.3.0

func BuildRepoUrl(owner, repo string) string

BuildRepoUrl - construct a URL for the given github repo

func ComputeFileChecksum

func ComputeFileChecksum(file string) (uint32, error)

ComputeFileChecksum - compute the crc32 checksum of a file

func Confirm

func Confirm(msg string, defaultVal bool, stdin io.Reader, stdout io.Writer) (bool, error)

Confirm - get a confirmation from the user. A "y" response will return true and an "n" response will return false

func CreateFile

func CreateFile(path string) (*os.File, error)

CreateFile - Creates a file and its directory if needed

func CreateTempDir

func CreateTempDir() error

CreateTempDir - Create a temporary directory

func DownloadFile

func DownloadFile(url, dst string) error

DownloadFile - download a file and save it to the specified destination

func DownloadRepo

func DownloadRepo(owner, repo, branch, dst string) error

DownloadRepo - download a zipped copy of the specified GitHub repo

func RemoveTempDir

func RemoveTempDir() error

RemoveTempDir - Remove the temporary directory

func RenderTemplateDir

func RenderTemplateDir(
	tmplDir,
	dstDir string,
	problem *EulerProblem,
	overwrite bool,
	stdin io.Reader,
	stdout io.Writer,
) error

RenderTemplateDir - Render all files in the tmplDir into dst

func SyncDirs

func SyncDirs(src, dst string, overwrite bool, stdin io.Reader, stdout io.Writer) error

SyncDirs - Sync a source directory to a destination

func SyncFiles

func SyncFiles(src, dst string, overwrite bool, stdin io.Reader, stdout io.Writer) error

SyncFiles - Sync a source file a destination If the destination exists and overwrite is false, the user is asked to confirm the operation.

func TempPath

func TempPath(relPath string) string

TempPath - Append a relative path onto eulercli's temporary directory

func Unzip

func Unzip(src, dst string) error

Unzip - Unzip a zip archive Taken from https://stackoverflow.com/questions/20357223/easy-way-to-unzip-file-with-golang

func ValidateProblemStr

func ValidateProblemStr(problemArgStr string) error

ValidateProblemStr - Validate that the given string can be parsed as an integer

func ValidateSingleProblemArg

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

ValidateSingleProblemArg - Validate that a command has been called with a valid problem argument

Types

type EulerProblem

type EulerProblem struct {
	ProblemNum       int
	PaddedProblemNum string
	ProblemText      string
	AnswerMD5        string
	Answer           string
}

EulerProblem - a structured type representing a project euler problem

func GetProblem

func GetProblem(problemNum int) (*EulerProblem, error)

GetProblem - return an EulerProblem instance corresponding to the given problem number

type MissingProblemError

type MissingProblemError struct {
	ProblemNum                 int
	LargestSupportedProblemNum int
}

MissingProblemError - used when the user requests a problem that doesn't exist

func (*MissingProblemError) Error

func (e *MissingProblemError) Error() string

Error - convert a MissingProblemError into a string

type ProblemArgError

type ProblemArgError struct {
	// contains filtered or unexported fields
}

ProblemArgError - returned by ValidateSingleProblemArg when the problem argument is not parseable

func (*ProblemArgError) Error

func (e *ProblemArgError) Error() string

Error - Convert a ProblemArgError into a string

Jump to

Keyboard shortcuts

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