Major changes: - Refactor CLI to accept injected I/O streams and filesystem (afero.Fs) for testing without touching the real filesystem - Add RunOptions struct and RunWithOptions() for configurable CLI execution - Add internal/scanner package with two-phase manifest generation: - Phase 1 (Enumeration): walk directories, collect metadata - Phase 2 (Scan): read contents, compute hashes, write manifest - Add internal/checker package for manifest verification with progress reporting and channel-based result streaming - Add mfer/builder.go for incremental manifest construction - Add --no-extra-files flag to check command to detect files not in manifest - Add timing summaries showing file count, size, elapsed time, and throughput - Add comprehensive tests using afero.MemMapFs (no real filesystem access) - Add contrib/usage.sh integration test script - Fix banner ASCII art alignment (consistent spacing) - Fix verbosity levels so summaries display at default log level - Update internal/log to support configurable output writers
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
var NO_COLOR bool
|
|
|
|
func init() {
|
|
NO_COLOR = false
|
|
if _, exists := os.LookupEnv("NO_COLOR"); exists {
|
|
NO_COLOR = true
|
|
}
|
|
}
|
|
|
|
// RunOptions contains all configuration for running the CLI application.
|
|
type RunOptions struct {
|
|
Appname string
|
|
Version string
|
|
Gitrev string
|
|
Args []string
|
|
Stdin io.Reader
|
|
Stdout io.Writer
|
|
Stderr io.Writer
|
|
Fs afero.Fs
|
|
}
|
|
|
|
// DefaultRunOptions returns RunOptions configured for normal CLI execution.
|
|
func DefaultRunOptions(appname, version, gitrev string) *RunOptions {
|
|
return &RunOptions{
|
|
Appname: appname,
|
|
Version: version,
|
|
Gitrev: gitrev,
|
|
Args: os.Args,
|
|
Stdin: os.Stdin,
|
|
Stdout: os.Stdout,
|
|
Stderr: os.Stderr,
|
|
Fs: afero.NewOsFs(),
|
|
}
|
|
}
|
|
|
|
// Run creates and runs the CLI application with default options.
|
|
func Run(appname, version, gitrev string) int {
|
|
return RunWithOptions(DefaultRunOptions(appname, version, gitrev))
|
|
}
|
|
|
|
// RunWithOptions creates and runs the CLI application with the given options.
|
|
func RunWithOptions(opts *RunOptions) int {
|
|
m := &CLIApp{
|
|
appname: opts.Appname,
|
|
version: opts.Version,
|
|
gitrev: opts.Gitrev,
|
|
exitCode: 0,
|
|
Stdin: opts.Stdin,
|
|
Stdout: opts.Stdout,
|
|
Stderr: opts.Stderr,
|
|
Fs: opts.Fs,
|
|
}
|
|
|
|
m.run(opts.Args)
|
|
return m.exitCode
|
|
}
|