(Fix): Removed unneccessary comments that my copilot generated.

This commit is contained in:
2025-11-22 10:17:28 +00:00
parent 8081085f87
commit 3caca0dfcb
8 changed files with 3 additions and 46 deletions

View File

@@ -80,7 +80,6 @@ func TestCompareIdenticalArchives(t *testing.T) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
// Create source directory
sourceDir := filepath.Join(tmpDir, "source") sourceDir := filepath.Join(tmpDir, "source")
os.Mkdir(sourceDir, 0755) os.Mkdir(sourceDir, 0755)
os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content"), 0644) os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content"), 0644)

View File

@@ -21,12 +21,10 @@ func TestCreateZip(t *testing.T) {
os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content1"), 0644) os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content1"), 0644)
os.WriteFile(filepath.Join(sourceDir, "file2.txt"), []byte("content2"), 0644) os.WriteFile(filepath.Join(sourceDir, "file2.txt"), []byte("content2"), 0644)
// Create subdirectory
subDir := filepath.Join(sourceDir, "subdir") subDir := filepath.Join(sourceDir, "subdir")
os.Mkdir(subDir, 0755) os.Mkdir(subDir, 0755)
os.WriteFile(filepath.Join(subDir, "file3.txt"), []byte("content3"), 0644) os.WriteFile(filepath.Join(subDir, "file3.txt"), []byte("content3"), 0644)
// Create ZIP
zipPath := filepath.Join(tmpDir, "test.zip") zipPath := filepath.Join(tmpDir, "test.zip")
config := &models.CompressConfig{ config := &models.CompressConfig{
SourcePath: sourceDir, SourcePath: sourceDir,
@@ -59,11 +57,9 @@ func TestCreateZipWithCompressionLevels(t *testing.T) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
// Create test file with compressible content
sourceDir := filepath.Join(tmpDir, "source") sourceDir := filepath.Join(tmpDir, "source")
os.Mkdir(sourceDir, 0755) os.Mkdir(sourceDir, 0755)
// Create a file with repetitive content (compresses well)
content := make([]byte, 10000) content := make([]byte, 10000)
for i := range content { for i := range content {
content[i] = byte(i % 10) content[i] = byte(i % 10)
@@ -402,11 +398,9 @@ func TestZipEmptyDirectory(t *testing.T) {
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
// Create empty directory
sourceDir := filepath.Join(tmpDir, "empty") sourceDir := filepath.Join(tmpDir, "empty")
os.Mkdir(sourceDir, 0755) os.Mkdir(sourceDir, 0755)
// Create ZIP
zipPath := filepath.Join(tmpDir, "empty.zip") zipPath := filepath.Join(tmpDir, "empty.zip")
config := &models.CompressConfig{ config := &models.CompressConfig{
SourcePath: sourceDir, SourcePath: sourceDir,
@@ -420,7 +414,6 @@ func TestZipEmptyDirectory(t *testing.T) {
t.Fatalf("createZip failed: %v", err) t.Fatalf("createZip failed: %v", err)
} }
// Verify ZIP was created
if _, err := os.Stat(zipPath); os.IsNotExist(err) { if _, err := os.Stat(zipPath); os.IsNotExist(err) {
t.Error("ZIP file was not created") t.Error("ZIP file was not created")
} }

View File

@@ -12,7 +12,6 @@ import (
"zipprine/internal/version" "zipprine/internal/version"
) )
// Run executes the CLI mode
func Run() bool { func Run() bool {
// Define flags // Define flags
compress := flag.String("compress", "", "Compress files/folders (source path)") compress := flag.String("compress", "", "Compress files/folders (source path)")
@@ -32,24 +31,19 @@ func Run() bool {
flag.Parse() flag.Parse()
// Show version
if *showVersion { if *showVersion {
fmt.Println(version.FullVersion()) fmt.Println(version.FullVersion())
return true return true
} }
// Show help
if *help { if *help {
printHelp() printHelp()
return true return true
} }
// Check if any CLI flags were provided
if flag.NFlag() == 0 { if flag.NFlag() == 0 {
return false // No flags, use interactive mode return false
} }
// Handle remote URL fetching
if *remoteURL != "" { if *remoteURL != "" {
if *output == "" { if *output == "" {
fmt.Println("❌ Error: --output is required when using --url") fmt.Println("❌ Error: --output is required when using --url")
@@ -68,7 +62,6 @@ func Run() bool {
return true return true
} }
// Handle compression
if *compress != "" { if *compress != "" {
if *output == "" { if *output == "" {
fmt.Println("❌ Error: --output is required for compression") fmt.Println("❌ Error: --output is required for compression")
@@ -105,7 +98,6 @@ func Run() bool {
return true return true
} }
// Handle extraction
if *extract != "" { if *extract != "" {
if *output == "" { if *output == "" {
fmt.Println("❌ Error: --output is required for extraction") fmt.Println("❌ Error: --output is required for extraction")
@@ -172,7 +164,6 @@ func Run() bool {
return true return true
} }
// If we get here, no valid operation was specified
fmt.Println("❌ Error: No valid operation specified. Use --help for usage information.") fmt.Println("❌ Error: No valid operation specified. Use --help for usage information.")
os.Exit(1) os.Exit(1)
return true return true

View File

@@ -15,7 +15,7 @@ import (
// FetchAndExtract downloads an archive from a URL and extracts it to the destination path // FetchAndExtract downloads an archive from a URL and extracts it to the destination path
func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bool) error { func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bool) error {
// Validate URL
parsedURL, err := url.Parse(archiveURL) parsedURL, err := url.Parse(archiveURL)
if err != nil { if err != nil {
return fmt.Errorf("invalid URL: %w", err) return fmt.Errorf("invalid URL: %w", err)
@@ -25,13 +25,11 @@ func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bo
return fmt.Errorf("only HTTP and HTTPS URLs are supported") return fmt.Errorf("only HTTP and HTTPS URLs are supported")
} }
// Extract filename from URL
filename := filepath.Base(parsedURL.Path) filename := filepath.Base(parsedURL.Path)
if filename == "" || filename == "." || filename == "/" { if filename == "" || filename == "." || filename == "/" {
filename = "archive.tmp" filename = "archive.tmp"
} }
// Create temporary directory
tempDir, err := os.MkdirTemp("", "zipprine-*") tempDir, err := os.MkdirTemp("", "zipprine-*")
if err != nil { if err != nil {
return fmt.Errorf("failed to create temp directory: %w", err) return fmt.Errorf("failed to create temp directory: %w", err)
@@ -40,7 +38,6 @@ func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bo
tempFile := filepath.Join(tempDir, filename) tempFile := filepath.Join(tempDir, filename)
// Download the file
fmt.Printf("📥 Downloading from %s...\n", archiveURL) fmt.Printf("📥 Downloading from %s...\n", archiveURL)
if err := downloadFile(tempFile, archiveURL); err != nil { if err := downloadFile(tempFile, archiveURL); err != nil {
return fmt.Errorf("failed to download file: %w", err) return fmt.Errorf("failed to download file: %w", err)
@@ -48,7 +45,6 @@ func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bo
fmt.Printf("✅ Download complete: %s\n", tempFile) fmt.Printf("✅ Download complete: %s\n", tempFile)
// Detect archive type
archiveType, err := archiver.DetectArchiveType(tempFile) archiveType, err := archiver.DetectArchiveType(tempFile)
if err != nil { if err != nil {
return fmt.Errorf("failed to detect archive type: %w", err) return fmt.Errorf("failed to detect archive type: %w", err)
@@ -60,7 +56,6 @@ func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bo
fmt.Printf("📦 Detected archive type: %s\n", archiveType) fmt.Printf("📦 Detected archive type: %s\n", archiveType)
// Extract the archive
fmt.Printf("📂 Extracting to %s...\n", destPath) fmt.Printf("📂 Extracting to %s...\n", destPath)
extractConfig := &models.ExtractConfig{ extractConfig := &models.ExtractConfig{
ArchivePath: tempFile, ArchivePath: tempFile,
@@ -80,14 +75,12 @@ func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bo
// downloadFile downloads a file from a URL to a local path with progress indication // downloadFile downloads a file from a URL to a local path with progress indication
func downloadFile(filepath, url string) error { func downloadFile(filepath, url string) error {
// Create the file
out, err := os.Create(filepath) out, err := os.Create(filepath)
if err != nil { if err != nil {
return err return err
} }
defer out.Close() defer out.Close()
// Get the data
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err
@@ -99,10 +92,8 @@ func downloadFile(filepath, url string) error {
return fmt.Errorf("bad status: %s", resp.Status) return fmt.Errorf("bad status: %s", resp.Status)
} }
// Get content length for progress
contentLength := resp.ContentLength contentLength := resp.ContentLength
// Create progress reader
var reader io.Reader = resp.Body var reader io.Reader = resp.Body
if contentLength > 0 { if contentLength > 0 {
reader = &progressReader{ reader = &progressReader{
@@ -119,7 +110,7 @@ func downloadFile(filepath, url string) error {
return err return err
} }
fmt.Println() // New line after progress fmt.Println()
return nil return nil
} }

View File

@@ -12,7 +12,6 @@ func getPathCompletions(input string) []string {
input = "." input = "."
} }
// Expand home directory
if strings.HasPrefix(input, "~") { if strings.HasPrefix(input, "~") {
home, err := os.UserHomeDir() home, err := os.UserHomeDir()
if err == nil { if err == nil {
@@ -20,20 +19,16 @@ func getPathCompletions(input string) []string {
} }
} }
// Get the directory and file pattern
dir := filepath.Dir(input) dir := filepath.Dir(input)
pattern := filepath.Base(input) pattern := filepath.Base(input)
// If input ends with /, we want to list that directory
if strings.HasSuffix(input, string(filepath.Separator)) { if strings.HasSuffix(input, string(filepath.Separator)) {
dir = input dir = input
pattern = "" pattern = ""
} }
// Read directory
entries, err := os.ReadDir(dir) entries, err := os.ReadDir(dir)
if err != nil { if err != nil {
// If can't read, try current directory
entries, err = os.ReadDir(".") entries, err = os.ReadDir(".")
if err != nil { if err != nil {
return []string{} return []string{}
@@ -63,7 +58,6 @@ func getPathCompletions(input string) []string {
completions = append(completions, fullPath) completions = append(completions, fullPath)
} }
// Limit to 15 suggestions
if len(completions) > 15 { if len(completions) > 15 {
completions = completions[:15] completions = completions[:15]
} }
@@ -85,13 +79,11 @@ func getArchiveCompletions(input string) []string {
archiveCompletions := []string{} archiveCompletions := []string{}
for _, path := range allCompletions { for _, path := range allCompletions {
// Keep directories
if strings.HasSuffix(path, string(filepath.Separator)) { if strings.HasSuffix(path, string(filepath.Separator)) {
archiveCompletions = append(archiveCompletions, path) archiveCompletions = append(archiveCompletions, path)
continue continue
} }
// Check if file has archive extension
ext := filepath.Ext(path) ext := filepath.Ext(path)
if archiveExts[ext] { if archiveExts[ext] {
archiveCompletions = append(archiveCompletions, path) archiveCompletions = append(archiveCompletions, path)

View File

@@ -228,7 +228,6 @@ func RunBatchExtractFlow() error {
fmt.Println(InfoStyle.Render(fmt.Sprintf("📂 Batch extracting %d archives...", len(configs)))) fmt.Println(InfoStyle.Render(fmt.Sprintf("📂 Batch extracting %d archives...", len(configs))))
fmt.Println() fmt.Println()
// Create batch config
batchConfig := &archiver.BatchExtractConfig{ batchConfig := &archiver.BatchExtractConfig{
Configs: configs, Configs: configs,
Parallel: parallel, Parallel: parallel,
@@ -246,7 +245,6 @@ func RunBatchExtractFlow() error {
errors := archiver.BatchExtract(batchConfig) errors := archiver.BatchExtract(batchConfig)
// Count successes
successCount := 0 successCount := 0
for _, err := range errors { for _, err := range errors {
if err == nil { if err == nil {

View File

@@ -21,7 +21,6 @@ func RunCompressFlow() error {
var verify bool var verify bool
var compressionLevel string var compressionLevel string
// Get current working directory
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
form := huh.NewForm( form := huh.NewForm(
@@ -124,14 +123,11 @@ func RunCompressFlow() error {
} }
} }
// Auto-generate output path if not provided
if outputPath == "" { if outputPath == "" {
sourceName := filepath.Base(sourcePath) sourceName := filepath.Base(sourcePath)
// Remove trailing slashes
sourceName = strings.TrimSuffix(sourceName, string(filepath.Separator)) sourceName = strings.TrimSuffix(sourceName, string(filepath.Separator))
// Determine file extension based on archive type
var extension string var extension string
switch models.ArchiveType(archiveTypeStr) { switch models.ArchiveType(archiveTypeStr) {
case models.ZIP: case models.ZIP:
@@ -146,7 +142,6 @@ func RunCompressFlow() error {
extension = ".zip" extension = ".zip"
} }
// Create output path in current working directory
outputPath = filepath.Join(cwd, sourceName+extension) outputPath = filepath.Join(cwd, sourceName+extension)
fmt.Println(InfoStyle.Render(fmt.Sprintf("📝 Auto-generated output: %s", outputPath))) fmt.Println(InfoStyle.Render(fmt.Sprintf("📝 Auto-generated output: %s", outputPath)))

View File

@@ -8,12 +8,10 @@ const (
Patch = 3 Patch = 3
) )
// Version returns the semantic version string
func Version() string { func Version() string {
return fmt.Sprintf("%d.%d.%d", Major, Minor, Patch) return fmt.Sprintf("%d.%d.%d", Major, Minor, Patch)
} }
// FullVersion returns the version with app name
func FullVersion() string { func FullVersion() string {
return fmt.Sprintf("Zipprine v%s", Version()) return fmt.Sprintf("Zipprine v%s", Version())
} }