simplify readme and make a force flag for local overrides
This commit is contained in:
+12
-6
@@ -19,7 +19,7 @@ var (
|
||||
Short: "Generate markdown documentation from directory structure",
|
||||
Long: `dirmd walks a directory and generates a markdown file with:
|
||||
|
||||
- Directory tree structure
|
||||
- Directory tree structure
|
||||
- All readable text files with their contents
|
||||
|
||||
Examples:
|
||||
@@ -27,12 +27,15 @@ Examples:
|
||||
# Create new documentation
|
||||
dirmd -o output.md ~/repos/myproject
|
||||
|
||||
# Append a single file
|
||||
# Append a single file
|
||||
dirmd -a -i README.md -o existing.md
|
||||
|
||||
# Append another directory
|
||||
dirmd -a -o existing.md ~/repos/anotherproject
|
||||
|
||||
# Overwrite existing local file
|
||||
dirmd -o output.md ~/repos/myproject -f
|
||||
|
||||
# Generate and upload to Proton Drive (default remote path /my-files/md/<filename>)
|
||||
dirmd -o output.md ~/repos/myproject --proton-drive
|
||||
|
||||
@@ -43,6 +46,7 @@ Examples:
|
||||
|
||||
outputPath string
|
||||
appendMode bool
|
||||
force bool
|
||||
singleFile string
|
||||
maxSize int64
|
||||
maxDepth int
|
||||
@@ -61,6 +65,7 @@ func Execute() {
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "", "output markdown file path (required)")
|
||||
rootCmd.Flags().BoolVarP(&appendMode, "append", "a", false, "append to existing output file")
|
||||
rootCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing output file (non-append mode)")
|
||||
rootCmd.Flags().StringVarP(&singleFile, "input-file", "i", "", "single file input (append mode only)")
|
||||
rootCmd.Flags().Int64Var(&maxSize, "max-size", config.DefaultMaxSize, "max file size in bytes")
|
||||
rootCmd.Flags().IntVar(&maxDepth, "max-depth", config.DefaultMaxDepth, "max directory recursion depth")
|
||||
@@ -80,6 +85,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
cfg := &config.Config{
|
||||
OutputPath: outputPath,
|
||||
AppendMode: appendMode,
|
||||
Force: force,
|
||||
MaxSize: maxSize,
|
||||
MaxDepth: maxDepth,
|
||||
Ignores: append(config.DefaultIgnores, ignorePatterns...),
|
||||
@@ -107,10 +113,10 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
cfg.AbsRoot = abs
|
||||
|
||||
// Non-append mode: output must not exist
|
||||
// Non-append mode: check for existing output file
|
||||
if !appendMode {
|
||||
if _, err := os.Stat(outputPath); err == nil {
|
||||
return fmt.Errorf("output file %s already exists (use -a to append)", outputPath)
|
||||
if _, err := os.Stat(outputPath); err == nil && !force {
|
||||
return fmt.Errorf("output file %s already exists (use -f to overwrite or -a to append)", outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +138,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
if protonDrive {
|
||||
remotePath := drivePath
|
||||
if remotePath == "" {
|
||||
remotePath = "/my-files/md/" + filepath.Base(outputPath)
|
||||
remotePath = "/my/files/md/" + filepath.Base(outputPath)
|
||||
}
|
||||
|
||||
if err := drive.CheckAuth(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user