(Fix): Removed unneccessary comments that my copilot generated.
This commit is contained in:
@@ -80,7 +80,6 @@ func TestCompareIdenticalArchives(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create source directory
|
||||
sourceDir := filepath.Join(tmpDir, "source")
|
||||
os.Mkdir(sourceDir, 0755)
|
||||
os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content"), 0644)
|
||||
|
||||
@@ -21,12 +21,10 @@ func TestCreateZip(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(sourceDir, "file1.txt"), []byte("content1"), 0644)
|
||||
os.WriteFile(filepath.Join(sourceDir, "file2.txt"), []byte("content2"), 0644)
|
||||
|
||||
// Create subdirectory
|
||||
subDir := filepath.Join(sourceDir, "subdir")
|
||||
os.Mkdir(subDir, 0755)
|
||||
os.WriteFile(filepath.Join(subDir, "file3.txt"), []byte("content3"), 0644)
|
||||
|
||||
// Create ZIP
|
||||
zipPath := filepath.Join(tmpDir, "test.zip")
|
||||
config := &models.CompressConfig{
|
||||
SourcePath: sourceDir,
|
||||
@@ -59,11 +57,9 @@ func TestCreateZipWithCompressionLevels(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create test file with compressible content
|
||||
sourceDir := filepath.Join(tmpDir, "source")
|
||||
os.Mkdir(sourceDir, 0755)
|
||||
|
||||
// Create a file with repetitive content (compresses well)
|
||||
content := make([]byte, 10000)
|
||||
for i := range content {
|
||||
content[i] = byte(i % 10)
|
||||
@@ -402,11 +398,9 @@ func TestZipEmptyDirectory(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create empty directory
|
||||
sourceDir := filepath.Join(tmpDir, "empty")
|
||||
os.Mkdir(sourceDir, 0755)
|
||||
|
||||
// Create ZIP
|
||||
zipPath := filepath.Join(tmpDir, "empty.zip")
|
||||
config := &models.CompressConfig{
|
||||
SourcePath: sourceDir,
|
||||
@@ -420,7 +414,6 @@ func TestZipEmptyDirectory(t *testing.T) {
|
||||
t.Fatalf("createZip failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify ZIP was created
|
||||
if _, err := os.Stat(zipPath); os.IsNotExist(err) {
|
||||
t.Error("ZIP file was not created")
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"zipprine/internal/version"
|
||||
)
|
||||
|
||||
// Run executes the CLI mode
|
||||
func Run() bool {
|
||||
// Define flags
|
||||
compress := flag.String("compress", "", "Compress files/folders (source path)")
|
||||
@@ -32,24 +31,19 @@ func Run() bool {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Show version
|
||||
if *showVersion {
|
||||
fmt.Println(version.FullVersion())
|
||||
return true
|
||||
}
|
||||
|
||||
// Show help
|
||||
if *help {
|
||||
printHelp()
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if any CLI flags were provided
|
||||
if flag.NFlag() == 0 {
|
||||
return false // No flags, use interactive mode
|
||||
return false
|
||||
}
|
||||
|
||||
// Handle remote URL fetching
|
||||
if *remoteURL != "" {
|
||||
if *output == "" {
|
||||
fmt.Println("❌ Error: --output is required when using --url")
|
||||
@@ -68,7 +62,6 @@ func Run() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Handle compression
|
||||
if *compress != "" {
|
||||
if *output == "" {
|
||||
fmt.Println("❌ Error: --output is required for compression")
|
||||
@@ -105,7 +98,6 @@ func Run() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Handle extraction
|
||||
if *extract != "" {
|
||||
if *output == "" {
|
||||
fmt.Println("❌ Error: --output is required for extraction")
|
||||
@@ -172,7 +164,6 @@ func Run() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// If we get here, no valid operation was specified
|
||||
fmt.Println("❌ Error: No valid operation specified. Use --help for usage information.")
|
||||
os.Exit(1)
|
||||
return true
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// FetchAndExtract downloads an archive from a URL and extracts it to the destination path
|
||||
func FetchAndExtract(archiveURL, destPath string, overwriteAll, preservePerms bool) error {
|
||||
// Validate URL
|
||||
|
||||
parsedURL, err := url.Parse(archiveURL)
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
// Extract filename from URL
|
||||
filename := filepath.Base(parsedURL.Path)
|
||||
if filename == "" || filename == "." || filename == "/" {
|
||||
filename = "archive.tmp"
|
||||
}
|
||||
|
||||
// Create temporary directory
|
||||
tempDir, err := os.MkdirTemp("", "zipprine-*")
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
// Download the file
|
||||
fmt.Printf("📥 Downloading from %s...\n", archiveURL)
|
||||
if err := downloadFile(tempFile, archiveURL); err != nil {
|
||||
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)
|
||||
|
||||
// Detect archive type
|
||||
archiveType, err := archiver.DetectArchiveType(tempFile)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
// Extract the archive
|
||||
fmt.Printf("📂 Extracting to %s...\n", destPath)
|
||||
extractConfig := &models.ExtractConfig{
|
||||
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
|
||||
func downloadFile(filepath, url string) error {
|
||||
// Create the file
|
||||
out, err := os.Create(filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Get the data
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -99,10 +92,8 @@ func downloadFile(filepath, url string) error {
|
||||
return fmt.Errorf("bad status: %s", resp.Status)
|
||||
}
|
||||
|
||||
// Get content length for progress
|
||||
contentLength := resp.ContentLength
|
||||
|
||||
// Create progress reader
|
||||
var reader io.Reader = resp.Body
|
||||
if contentLength > 0 {
|
||||
reader = &progressReader{
|
||||
@@ -119,7 +110,7 @@ func downloadFile(filepath, url string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println() // New line after progress
|
||||
fmt.Println()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ func getPathCompletions(input string) []string {
|
||||
input = "."
|
||||
}
|
||||
|
||||
// Expand home directory
|
||||
if strings.HasPrefix(input, "~") {
|
||||
home, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
@@ -20,20 +19,16 @@ func getPathCompletions(input string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the directory and file pattern
|
||||
dir := filepath.Dir(input)
|
||||
pattern := filepath.Base(input)
|
||||
|
||||
// If input ends with /, we want to list that directory
|
||||
if strings.HasSuffix(input, string(filepath.Separator)) {
|
||||
dir = input
|
||||
pattern = ""
|
||||
}
|
||||
|
||||
// Read directory
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
// If can't read, try current directory
|
||||
entries, err = os.ReadDir(".")
|
||||
if err != nil {
|
||||
return []string{}
|
||||
@@ -63,7 +58,6 @@ func getPathCompletions(input string) []string {
|
||||
completions = append(completions, fullPath)
|
||||
}
|
||||
|
||||
// Limit to 15 suggestions
|
||||
if len(completions) > 15 {
|
||||
completions = completions[:15]
|
||||
}
|
||||
@@ -85,13 +79,11 @@ func getArchiveCompletions(input string) []string {
|
||||
archiveCompletions := []string{}
|
||||
|
||||
for _, path := range allCompletions {
|
||||
// Keep directories
|
||||
if strings.HasSuffix(path, string(filepath.Separator)) {
|
||||
archiveCompletions = append(archiveCompletions, path)
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if file has archive extension
|
||||
ext := filepath.Ext(path)
|
||||
if archiveExts[ext] {
|
||||
archiveCompletions = append(archiveCompletions, path)
|
||||
|
||||
@@ -228,7 +228,6 @@ func RunBatchExtractFlow() error {
|
||||
fmt.Println(InfoStyle.Render(fmt.Sprintf("📂 Batch extracting %d archives...", len(configs))))
|
||||
fmt.Println()
|
||||
|
||||
// Create batch config
|
||||
batchConfig := &archiver.BatchExtractConfig{
|
||||
Configs: configs,
|
||||
Parallel: parallel,
|
||||
@@ -246,7 +245,6 @@ func RunBatchExtractFlow() error {
|
||||
|
||||
errors := archiver.BatchExtract(batchConfig)
|
||||
|
||||
// Count successes
|
||||
successCount := 0
|
||||
for _, err := range errors {
|
||||
if err == nil {
|
||||
|
||||
@@ -21,7 +21,6 @@ func RunCompressFlow() error {
|
||||
var verify bool
|
||||
var compressionLevel string
|
||||
|
||||
// Get current working directory
|
||||
cwd, _ := os.Getwd()
|
||||
|
||||
form := huh.NewForm(
|
||||
@@ -124,14 +123,11 @@ func RunCompressFlow() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-generate output path if not provided
|
||||
if outputPath == "" {
|
||||
sourceName := filepath.Base(sourcePath)
|
||||
|
||||
// Remove trailing slashes
|
||||
sourceName = strings.TrimSuffix(sourceName, string(filepath.Separator))
|
||||
|
||||
// Determine file extension based on archive type
|
||||
var extension string
|
||||
switch models.ArchiveType(archiveTypeStr) {
|
||||
case models.ZIP:
|
||||
@@ -146,7 +142,6 @@ func RunCompressFlow() error {
|
||||
extension = ".zip"
|
||||
}
|
||||
|
||||
// Create output path in current working directory
|
||||
outputPath = filepath.Join(cwd, sourceName+extension)
|
||||
|
||||
fmt.Println(InfoStyle.Render(fmt.Sprintf("📝 Auto-generated output: %s", outputPath)))
|
||||
|
||||
@@ -8,12 +8,10 @@ const (
|
||||
Patch = 3
|
||||
)
|
||||
|
||||
// Version returns the semantic version string
|
||||
func Version() string {
|
||||
return fmt.Sprintf("%d.%d.%d", Major, Minor, Patch)
|
||||
}
|
||||
|
||||
// FullVersion returns the version with app name
|
||||
func FullVersion() string {
|
||||
return fmt.Sprintf("Zipprine v%s", Version())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user