Add dryrun flag -n
This commit is contained in:
@@ -167,6 +167,24 @@ func generateS3HTML(entries []indexgen.FileEntry, opts *indexgen.Options) error
|
||||
return entries[i].Name < entries[j].Name
|
||||
})
|
||||
|
||||
// Determine output file
|
||||
outputFile := opts.OutputFile
|
||||
if outputFile == "" {
|
||||
outputFile = indexgen.DefaultOutputFile
|
||||
}
|
||||
|
||||
if opts.DryRun {
|
||||
// Dry run mode: show what would be written
|
||||
fmt.Printf("Would write S3 index file: %s\n", outputFile)
|
||||
fmt.Printf("S3 bucket: %s\n", opts.TopDir)
|
||||
fmt.Printf("Objects found: %d\n", len(entries))
|
||||
for _, entry := range entries {
|
||||
fmt.Printf(" object: %s (%s)\n", entry.Name, entry.SizePretty)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Normal mode: actually write the file
|
||||
// Get the HTML template
|
||||
tmpl := indexgen.GetHTMLTemplate()
|
||||
if tmpl == nil {
|
||||
@@ -186,12 +204,6 @@ func generateS3HTML(entries []indexgen.FileEntry, opts *indexgen.Options) error
|
||||
Hostname: "S3 Bucket", // Could be improved to show actual endpoint
|
||||
}
|
||||
|
||||
// Determine output file
|
||||
outputFile := opts.OutputFile
|
||||
if outputFile == "" {
|
||||
outputFile = indexgen.DefaultOutputFile
|
||||
}
|
||||
|
||||
// Create output file
|
||||
file, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
@@ -217,6 +229,7 @@ func main() {
|
||||
var excludeRegexStr string
|
||||
var directory string
|
||||
var s3URL string
|
||||
var dryRun bool
|
||||
|
||||
// Set defaults
|
||||
opts.DirAppend = true
|
||||
@@ -227,6 +240,7 @@ func main() {
|
||||
flag.StringVar(&directory, "d", "", "local directory to process")
|
||||
flag.StringVar(&s3URL, "s3", "", "S3 URL to process")
|
||||
flag.StringVar(&opts.Filter, "f", "*", "only include files matching glob")
|
||||
flag.BoolVar(&dryRun, "n", false, "dry run: show what would be written without actually writing")
|
||||
flag.StringVar(&excludeRegexStr, "x", "", "exclude files matching regular expression")
|
||||
flag.BoolVar(&opts.Verbose, "v", false, "verbosely list every processed file")
|
||||
|
||||
@@ -268,6 +282,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Set dry run flag
|
||||
opts.DryRun = dryRun
|
||||
|
||||
if s3URL != "" {
|
||||
// Parse S3 URL
|
||||
s3Config, err := parseS3URL(s3URL)
|
||||
|
||||
Reference in New Issue
Block a user