fix pre delete dirmd set dir bug and implement last git sha and commit#
This commit is contained in:
+11
-4
@@ -30,7 +30,7 @@ Examples:
|
||||
# Create new documentation (writes index.md inside ./docs/)
|
||||
dirmd -o ./docs ~/repos/myproject
|
||||
|
||||
# Overwrite existing output directory
|
||||
# Overwrite existing output directory (DELETES everything in it first)
|
||||
dirmd -o ./docs ~/repos/myproject -f
|
||||
|
||||
# Append a single file
|
||||
@@ -86,7 +86,7 @@ func Execute() {
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "output directory (required)")
|
||||
rootCmd.Flags().BoolVarP(&appendMode, "append", "a", false, "append to existing index.md")
|
||||
rootCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing output directory")
|
||||
rootCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing output directory (deletes all contents)")
|
||||
rootCmd.Flags().StringVar(&singleFile, "input-file", "", "single file input (append mode only)")
|
||||
rootCmd.Flags().BoolVarP(&tuiMode, "interactive", "i", false, "launch interactive TUI configuration wizard")
|
||||
rootCmd.Flags().Int64Var(&maxSize, "max-size", config.DefaultMaxSize, "max file size in bytes")
|
||||
@@ -173,9 +173,16 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("failed to resolve output path: %w", err)
|
||||
}
|
||||
|
||||
// Handle output directory existence
|
||||
if !appendMode {
|
||||
if _, err := os.Stat(absOutput); err == nil && !force {
|
||||
return fmt.Errorf("output directory %s already exists (use -f to overwrite)", absOutput)
|
||||
if _, err := os.Stat(absOutput); err == nil {
|
||||
if !force {
|
||||
return fmt.Errorf("output directory %s already exists (use -f to overwrite)", absOutput)
|
||||
}
|
||||
// FORCE MODE: Always delete the entire directory and recreate it fresh
|
||||
if err := os.RemoveAll(absOutput); err != nil {
|
||||
return fmt.Errorf("failed to remove existing output directory: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user