add .dirmd and other metadata
This commit is contained in:
+22
-39
@@ -27,33 +27,24 @@ Output is always written to a directory specified by -o.
|
||||
|
||||
Examples:
|
||||
|
||||
# Create new documentation (writes index.md inside ./docs/)
|
||||
# Create new documentation
|
||||
dirmd -o ./docs ~/repos/myproject
|
||||
|
||||
# Overwrite existing output directory (DELETES everything in it first)
|
||||
# Overwrite existing output directory (deletes all contents)
|
||||
dirmd -o ./docs ~/repos/myproject -f
|
||||
|
||||
# Append a single file
|
||||
dirmd -a -i README.md -o ./docs
|
||||
|
||||
# Vertical slices (root index.md + one markdown per top-level dir)
|
||||
# Vertical slices
|
||||
dirmd -o ./docs ~/repos/myproject --vertical-slices
|
||||
|
||||
# Skip frontend files
|
||||
dirmd -o ./docs ~/repos/myproject --skip-frontend
|
||||
|
||||
# Frontend only
|
||||
dirmd -o ./docs ~/repos/myproject --frontend-only
|
||||
|
||||
# Omit test files and test blocks
|
||||
dirmd -o ./docs ~/repos/myproject --omit-test
|
||||
# Include instructions from .dirmd
|
||||
dirmd -o ./docs ~/repos/myproject --instructions
|
||||
|
||||
# Generate and upload to Proton Drive
|
||||
dirmd -o ./docs ~/repos/myproject --proton-drive
|
||||
|
||||
# Generate and upload to a specific remote path
|
||||
dirmd -o ./docs ~/repos/myproject --proton-drive --drive-path /my-files/docs/api
|
||||
|
||||
# Interactive TUI mode
|
||||
dirmd --tui`,
|
||||
RunE: run,
|
||||
@@ -75,6 +66,7 @@ Examples:
|
||||
omitTest bool
|
||||
omitMd bool
|
||||
tuiMode bool
|
||||
instructions bool
|
||||
)
|
||||
|
||||
func Execute() {
|
||||
@@ -100,6 +92,7 @@ func init() {
|
||||
rootCmd.Flags().BoolVar(&frontendOnly, "frontend-only", false, "include only frontend file types and README.md")
|
||||
rootCmd.Flags().BoolVar(&omitTest, "omit-test", false, "exclude test files (Go *_test.go, Java *Test.java) and strip #[cfg(test)] blocks from Rust")
|
||||
rootCmd.Flags().BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md")
|
||||
rootCmd.Flags().BoolVar(&instructions, "instructions", false, "include .dirmd instructions file if present in root")
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) error {
|
||||
@@ -133,20 +126,21 @@ 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...),
|
||||
Extensions: excludedExts,
|
||||
ProtonDrive: protonDrive,
|
||||
DrivePath: drivePath,
|
||||
VerticalSlices: verticalSlices,
|
||||
SkipFrontend: skipFrontend,
|
||||
FrontendOnly: frontendOnly,
|
||||
OmitTest: omitTest,
|
||||
OmitMd: omitMd,
|
||||
OutputPath: outputPath,
|
||||
AppendMode: appendMode,
|
||||
Force: force,
|
||||
MaxSize: maxSize,
|
||||
MaxDepth: maxDepth,
|
||||
Ignores: append(config.DefaultIgnores, ignorePatterns...),
|
||||
Extensions: excludedExts,
|
||||
ProtonDrive: protonDrive,
|
||||
DrivePath: drivePath,
|
||||
VerticalSlices: verticalSlices,
|
||||
SkipFrontend: skipFrontend,
|
||||
FrontendOnly: frontendOnly,
|
||||
OmitTest: omitTest,
|
||||
OmitMd: omitMd,
|
||||
IncludeInstructions: instructions,
|
||||
}
|
||||
|
||||
if singleFile != "" {
|
||||
@@ -173,13 +167,11 @@ 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 {
|
||||
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)
|
||||
}
|
||||
@@ -209,7 +201,6 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "generated %d files in %s\n", len(generated), absOutput)
|
||||
|
||||
if protonDrive {
|
||||
@@ -217,27 +208,22 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
if remoteDir == "" {
|
||||
remoteDir = "/my-files/md/" + filepath.Base(absOutput)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if err := drive.UploadDir(absOutput, remoteDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
fmt.Fprintln(os.Stderr, "local files were written successfully, but upload failed")
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "uploaded %s to %s on Proton Drive\n", absOutput, remoteDir)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
indexPath := filepath.Join(absOutput, indexBasename)
|
||||
|
||||
if err := renderer.Write(result, indexPath, appendMode, cfg.SingleFile); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -249,19 +235,16 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
if remoteDir == "" {
|
||||
remoteDir = "/my-files/md/" + filepath.Base(absOutput)
|
||||
}
|
||||
|
||||
if err := drive.CheckAuth(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
fmt.Fprintln(os.Stderr, "local file was written successfully, but upload was skipped")
|
||||
return err
|
||||
}
|
||||
|
||||
if err := drive.UploadDir(absOutput, remoteDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
fmt.Fprintln(os.Stderr, "local file was written successfully, but upload failed")
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "uploaded %s to %s on Proton Drive\n", absOutput, remoteDir)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user