finished vertical-.slices

This commit is contained in:
Bartal Laearsson
2026-08-07 23:10:42 +01:00
parent 8c39068453
commit 6fbb9bf983
4 changed files with 504 additions and 74 deletions
+51 -11
View File
@@ -36,7 +36,10 @@ Examples:
# Overwrite existing local file
dirmd -o output.md ~/repos/myproject -f
# Generate and upload to Proton Drive (default remote path /my-files/md/<filename>)
# Generate with vertical slices (root + one file per top-level dir)
dirmd -o output.md ~/repos/myproject --vertical-slices
# Generate and upload to Proton Drive
dirmd -o output.md ~/repos/myproject --proton-drive
# Generate and upload to a specific remote path
@@ -54,6 +57,7 @@ Examples:
extensions []string
protonDrive bool
drivePath string
verticalSlices bool
)
func Execute() {
@@ -73,6 +77,7 @@ func init() {
rootCmd.Flags().StringArrayVar(&extensions, "extensions", nil, "additional file extensions to skip (repeatable)")
rootCmd.Flags().BoolVar(&protonDrive, "proton-drive", false, "upload output to Proton Drive after writing locally")
rootCmd.Flags().StringVar(&drivePath, "drive-path", "", "full remote path on Proton Drive (e.g. /my-files/md/report.md). Requires --proton-drive")
rootCmd.Flags().BoolVar(&verticalSlices, "vertical-slices", false, "split output into root file + one markdown per top-level directory")
rootCmd.MarkPersistentFlagRequired("output")
}
@@ -82,16 +87,25 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("--drive-path requires --proton-drive")
}
if verticalSlices && appendMode {
return fmt.Errorf("--vertical-slices cannot be used with --append")
}
if verticalSlices && singleFile != "" {
return fmt.Errorf("--vertical-slices cannot be used with --input-file")
}
cfg := &config.Config{
OutputPath: outputPath,
AppendMode: appendMode,
Force: force,
MaxSize: maxSize,
MaxDepth: maxDepth,
Ignores: append(config.DefaultIgnores, ignorePatterns...),
Extensions: append(config.DefaultExts, extensions...),
ProtonDrive: protonDrive,
DrivePath: drivePath,
OutputPath: outputPath,
AppendMode: appendMode,
Force: force,
MaxSize: maxSize,
MaxDepth: maxDepth,
Ignores: append(config.DefaultIgnores, ignorePatterns...),
Extensions: append(config.DefaultExts, extensions...),
ProtonDrive: protonDrive,
DrivePath: drivePath,
VerticalSlices: verticalSlices,
}
if singleFile != "" {
@@ -113,7 +127,6 @@ func run(cmd *cobra.Command, args []string) error {
}
cfg.AbsRoot = abs
// Non-append mode: check for existing output file
if !appendMode {
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)
@@ -129,6 +142,33 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("no readable text files found in %s", cfg.AbsRoot)
}
if verticalSlices {
generated, err := renderer.WriteSlices(result, outputPath)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "generated %d files\n", len(generated))
if protonDrive {
if err := drive.CheckAuth(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
fmt.Fprintln(os.Stderr, "local files were written successfully, but upload was skipped")
return err
}
for _, path := range generated {
if err := drive.Upload(path, "/my-files/md/"+filepath.Base(path)); err != nil {
fmt.Fprintf(os.Stderr, "error uploading %s: %v\n", path, err)
} else {
fmt.Fprintf(os.Stderr, "uploaded %s to Proton Drive\n", path)
}
}
}
return nil
}
if err := renderer.Write(result, outputPath, appendMode, cfg.SingleFile); err != nil {
return err
}