cmd

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package cmd implements the command-line interface for WarpDL. It provides commands for downloading files, managing downloads, controlling the daemon, and handling extensions.

Index

Constants

View Source
const (
	DEF_MAX_PARTS   = 200
	DEF_MAX_CONNS   = 24
	DEF_TIMEOUT     = time.Second * 30
	DEF_TIMEOUT_SEC = 30 // timeout in seconds for CLI flag
	DEF_MAX_RETRIES = 5
	DEF_RETRY_DELAY = 500 // milliseconds
	DEF_PORT        = common.DefaultTCPPort
)
View Source
const (
	ListDescription = `` /* 175-byte string literal not displayed */

	InfoDescription = `` /* 179-byte string literal not displayed */

	DownloadDescription = `` /* 744-byte string literal not displayed */

	ResumeDescription = `` /* 200-byte string literal not displayed */

	FlushDescription = `` /* 176-byte string literal not displayed */

)
View Source
const CMD_HELP_TEMPL = `` /* 252-byte string literal not displayed */
View Source
const DESCRIPTION = `` /* 238-byte string literal not displayed */
View Source
const HELP_TEMPL = `` /* 611-byte string literal not displayed */

Variables

View Source
var (
	// ErrInputFileNotFound is returned when the input file does not exist.
	ErrInputFileNotFound = errors.New("input file not found")
	// ErrInputFilePermission is returned when the input file cannot be read due to permissions.
	ErrInputFilePermission = errors.New("permission denied reading input file")
	// ErrInputFileEmpty is returned when the input file contains no valid URLs.
	ErrInputFileEmpty = errors.New("input file contains no valid URLs")
)

Sentinel errors for input file parsing.

View Source
var ErrDaemonAlreadyRunning = errors.New("daemon already running")

ErrDaemonAlreadyRunning indicates another daemon instance is already running.

View Source
var UserAgents = map[string]string{
	"warp":    warplib.DEF_USER_AGENT,
	"firefox": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0",
	"chrome":  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
	"edge":    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
}

Functions

func AppendCookieHeader added in v1.3.23

func AppendCookieHeader(headers warplib.Headers, cookies []string) (warplib.Headers, error)

AppendCookieHeader parses cookie flags and appends the resulting Cookie header to the given headers slice. If cookies is empty, returns headers unchanged. Returns an error if any cookie is malformed.

func CleanupStalePidFile added in v1.3.1

func CleanupStalePidFile() error

CleanupStalePidFile checks if a PID file exists and removes it if the process is no longer running. Returns ErrDaemonAlreadyRunning if another daemon instance is still active.

func Execute

func Execute(args []string, bArgs BuildArgs) error

Execute initializes and runs the CLI application with the provided arguments. It configures all available commands (download, resume, list, daemon, ext, etc.) and their respective flags, then executes the appropriate command based on user input. The default action is the download command when no subcommand is specified. It returns any error encountered during command execution.

func GetApp added in v1.3.19

func GetApp(bArgs BuildArgs) *cli.App

GetApp returns the configured CLI application for documentation generation and other programmatic uses. It builds the complete command structure with all flags, descriptions, and help templates. This function is useful when you need access to the app structure without running it (e.g., for generating documentation or inspecting available commands).

func ParseCookieFlags added in v1.3.23

func ParseCookieFlags(flags []string) (warplib.Header, error)

ParseCookieFlags converts --cookie flag values into a Cookie header. Input: ["session=abc", "user=xyz"] Output: Header{Key: "Cookie", Value: "session=abc; user=xyz"}

Returns an empty Header if flags is empty. Returns an error if any cookie is malformed (missing '=').

func ReadPidFile added in v1.2.0

func ReadPidFile() (int, error)

ReadPidFile reads and returns the PID from the PID file.

func RegisterHandlers

func RegisterHandlers(client *warpcli.Client, contentLength int64)

RegisterHandlers maintains backward compatibility for fresh downloads.

func RegisterHandlersWithProgress added in v1.3.21

func RegisterHandlersWithProgress(client *warpcli.Client, contentLength int64, initialProgress int64)

RegisterHandlersWithProgress registers all download event handlers with initial progress for resume scenarios.

func RemovePidFile added in v1.2.0

func RemovePidFile() error

RemovePidFile removes the PID file.

func WritePidFile added in v1.2.0

func WritePidFile() error

WritePidFile writes the current process ID to the PID file.

Types

type BatchDownloadClient added in v1.3.37

type BatchDownloadClient interface {
	Download(url, fileName, dir string, opts *warpcli.DownloadOpts) (*common.DownloadResponse, error)
	Close() error
}

BatchDownloadClient defines the interface for download operations. This interface is satisfied by warpcli.Client and allows for testing.

type BatchDownloadOpts added in v1.3.37

type BatchDownloadOpts struct {
	// DownloadDir is the directory where files will be saved.
	DownloadDir string
	// DownloadOpts contains additional options passed to each download.
	DownloadOpts *warpcli.DownloadOpts
}

BatchDownloadOpts contains options for batch download operations.

type BatchError added in v1.3.37

type BatchError struct {
	// URL is the URL that failed to download.
	URL string
	// Reason is a human-readable error message describing why the download failed.
	Reason string
}

BatchError represents an error that occurred during a specific URL download.

func NewBatchError added in v1.3.37

func NewBatchError(url string, err error) BatchError

NewBatchError creates a BatchError from a URL and an error.

type BatchResult added in v1.3.37

type BatchResult struct {
	// Succeeded is the count of successful downloads.
	Succeeded int
	// Failed is the count of failed downloads.
	Failed int
	// Total is the total number of URLs processed.
	Total int
	// Errors contains details about each failed download.
	Errors []BatchError
	// SkippedURLs contains URLs that were skipped during input file parsing.
	SkippedURLs []SkippedURL
	// Submissions contains the successfully-submitted downloads.
	Submissions []BatchSubmission
}

BatchResult contains the results of a batch download operation. It tracks success/failure counts and provides methods for result aggregation.

func DownloadBatch added in v1.3.37

func DownloadBatch(client BatchDownloadClient, inputFilePath string, directURLs []string, opts *BatchDownloadOpts) (*BatchResult, error)

DownloadBatch downloads multiple URLs from an input file and/or direct URL arguments. It continues processing even if individual downloads fail. Invalid URLs (e.g., non-http/https) are skipped with warnings logged.

Parameters:

  • client: the download client to use
  • inputFilePath: path to input file with URLs (empty string to skip)
  • directURLs: additional URLs provided directly as arguments
  • opts: batch download options

Returns the batch result with success/failure counts, skipped URLs, and any errors encountered.

func NewBatchResult added in v1.3.37

func NewBatchResult(total int) *BatchResult

NewBatchResult creates a new BatchResult with the specified total count.

func (*BatchResult) AddError added in v1.3.37

func (r *BatchResult) AddError(url string, err error)

AddError records a download failure with the URL and error message.

func (*BatchResult) AddSuccess added in v1.3.37

func (r *BatchResult) AddSuccess()

AddSuccess increments the success count.

func (*BatchResult) ConvertSuccessToError added in v1.4.3

func (r *BatchResult) ConvertSuccessToError(url string, err error)

ConvertSuccessToError changes one accepted submission into a terminal failure.

func (*BatchResult) HasErrors added in v1.3.37

func (r *BatchResult) HasErrors() bool

HasErrors returns true if any downloads failed.

func (*BatchResult) IsSuccess added in v1.3.37

func (r *BatchResult) IsSuccess() bool

IsSuccess returns true if all downloads succeeded (no failures).

func (*BatchResult) String added in v1.3.37

func (r *BatchResult) String() string

String returns a formatted summary of the batch download results. The summary includes total count, succeeded/failed counts, skipped URLs warnings, and error details.

type BatchSubmission added in v1.4.3

type BatchSubmission struct {
	URL           string
	DownloadID    string
	SavePath      string
	ContentLength int64
}

BatchSubmission tracks a successfully submitted download request.

type BuildArgs

type BuildArgs struct {
	// Version is the semantic version of the application.
	Version string
	// BuildType indicates the build variant (e.g., "release", "debug", "snapshot").
	BuildType string
	// Date is the build timestamp in a human-readable format.
	Date string
	// Commit is the git commit hash from which the build was created.
	Commit string
}

BuildArgs contains build-time information passed to the CLI application. These values are typically injected during the build process via ldflags and are used to display version and build information to users.

type DaemonComponents added in v1.3.18

type DaemonComponents struct {
	CookieManager *credman.CookieManager
	ExtEngine     *extl.Engine
	Manager       *warplib.Manager
	Api           *api.Api
	Server        *server.Server
	Scheduler     *scheduler.Scheduler
	// contains filtered or unexported fields
}

DaemonComponents holds all initialized daemon components. This allows for unified initialization and cleanup across console mode and Windows service mode.

func (*DaemonComponents) Close added in v1.3.18

func (c *DaemonComponents) Close()

Close releases all daemon component resources in reverse order of initialization. This ensures proper cleanup regardless of how the daemon was started.

type InputFileError added in v1.3.37

type InputFileError struct {
	Path string
	Err  error
}

InputFileError wraps input file errors with additional context.

func NewInputFileError added in v1.3.37

func NewInputFileError(path string, err error) *InputFileError

NewInputFileError creates a new InputFileError with the given path and error.

func (*InputFileError) Error added in v1.3.37

func (e *InputFileError) Error() string

func (*InputFileError) Unwrap added in v1.3.37

func (e *InputFileError) Unwrap() error

type InvalidLine added in v1.3.37

type InvalidLine struct {
	// LineNumber is the 1-indexed line number in the input file.
	LineNumber int
	// Content is the trimmed content of the invalid line.
	Content string
	// Reason explains why the line was considered invalid.
	Reason string
}

InvalidLine represents a line in the input file that failed validation.

type ParseResult added in v1.3.37

type ParseResult struct {
	// URLs contains the parsed URLs from the file.
	URLs []string
	// SkippedLines is the count of comment lines that were skipped.
	SkippedLines int
	// TotalLines is the total number of lines in the file.
	TotalLines int
	// InvalidLines contains lines that failed URL validation.
	InvalidLines []InvalidLine
}

ParseResult holds the result of parsing an input file.

func ParseInputFile added in v1.3.37

func ParseInputFile(filePath string) (*ParseResult, error)

ParseInputFile reads an input file and extracts URLs. It skips empty lines and comment lines (starting with #). Leading and trailing whitespace is trimmed from each line. URLs are validated to ensure they start with http:// or https://. Invalid URLs are tracked with line numbers for error reporting.

Errors returned:

  • ErrInputFileNotFound: file does not exist
  • ErrInputFilePermission: cannot read file due to permissions
  • ErrInputFileEmpty: file contains no valid URLs (only comments/empty lines/invalid URLs)

type SkippedURL added in v1.3.37

type SkippedURL struct {
	// LineNumber is the 1-indexed line number in the input file.
	LineNumber int
	// Content is the content of the skipped line.
	Content string
	// Reason explains why the line was skipped.
	Reason string
}

SkippedURL represents a URL that was skipped during input file parsing.

type SpeedCounter

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

func NewSpeedCounter

func NewSpeedCounter(refreshRate time.Duration) *SpeedCounter

func (*SpeedCounter) IncrBy

func (s *SpeedCounter) IncrBy(n int)

func (*SpeedCounter) SetBar

func (s *SpeedCounter) SetBar(bar *mpb.Bar)

func (*SpeedCounter) Start

func (s *SpeedCounter) Start()

func (*SpeedCounter) Stop

func (s *SpeedCounter) Stop()

Directories

Path Synopsis
Package common provides shared utilities and helper functions for CLI commands.
Package common provides shared utilities and helper functions for CLI commands.
Package nativehost provides CLI commands for managing native messaging host integration.
Package nativehost provides CLI commands for managing native messaging host integration.

Jump to

Keyboard shortcuts

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