remove append#

This commit is contained in:
2026-08-27 19:07:53 +01:00
parent adc276c28a
commit 8bfd6b22c5
3 changed files with 38 additions and 72 deletions
+24 -55
View File
@@ -27,52 +27,28 @@ func Generate(cfg *config.Config) GenerateResult {
}
cfg.AbsRoot = abs
var outputDir string
if cfg.AppendMode || cfg.SingleFile {
absOutput, err := filepath.Abs(cfg.OutputPath)
if err != nil {
result.Error = fmt.Errorf("resolve output path: %w", err)
return result
}
if !cfg.AppendMode {
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
result.Error = fmt.Errorf("output %s exists (enable force or append)", absOutput)
return result
}
}
dir := filepath.Dir(absOutput)
if err := os.MkdirAll(dir, 0755); err != nil {
result.Error = fmt.Errorf("create output dir: %w", err)
return result
}
outputDir = absOutput
} else {
absOutput, err := filepath.Abs(cfg.OutputPath)
if err != nil {
result.Error = fmt.Errorf("resolve output path: %w", err)
return result
}
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
if info, err2 := os.Stat(absOutput); err2 == nil && !info.IsDir() {
result.Error = fmt.Errorf("output %s exists and is not a directory (enable force)", absOutput)
return result
}
}
if err := os.MkdirAll(absOutput, 0755); err != nil {
result.Error = fmt.Errorf("create output dir: %w", err)
return result
}
cfg.OutputPath = absOutput
outputDir = absOutput
absOutput, err := filepath.Abs(cfg.OutputPath)
if err != nil {
result.Error = fmt.Errorf("resolve output path: %w", err)
return result
}
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
if info, err2 := os.Stat(absOutput); err2 == nil && !info.IsDir() {
result.Error = fmt.Errorf("output %s exists and is not a directory (enable force)", absOutput)
return result
}
result.Error = fmt.Errorf("output %s exists (enable force)", absOutput)
return result
}
if err := os.MkdirAll(absOutput, 0755); err != nil {
result.Error = fmt.Errorf("create output dir: %w", err)
return result
}
cfg.OutputPath = absOutput
walkResult, err := walker.Run(cfg)
if err != nil {
result.Error = err
@@ -94,12 +70,8 @@ func Generate(cfg *config.Config) GenerateResult {
}
result.Files = generated
} else {
indexPath := cfg.OutputPath
if !cfg.AppendMode && !cfg.SingleFile {
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
}
if err := renderer.Write(walkResult, indexPath, cfg.AppendMode, cfg.SingleFile); err != nil {
indexPath := filepath.Join(cfg.OutputPath, "index_"+repoName+".md")
if err := renderer.Write(walkResult, indexPath, false, false); err != nil {
result.Error = err
return result
}
@@ -109,7 +81,7 @@ func Generate(cfg *config.Config) GenerateResult {
if cfg.ProtonDrive {
remoteDir := cfg.DrivePath
if remoteDir == "" {
remoteDir = "/my-files/md/" + filepath.Base(outputDir)
remoteDir = "/my-files/md/" + filepath.Base(cfg.OutputPath)
}
if err := drive.CheckAuth(); err != nil {
@@ -123,10 +95,7 @@ func Generate(cfg *config.Config) GenerateResult {
return result
}
} else {
indexPath := cfg.OutputPath
if !cfg.AppendMode && !cfg.SingleFile {
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
}
indexPath := filepath.Join(cfg.OutputPath, "index_"+repoName+".md")
if err := drive.Upload(indexPath, remoteDir); err != nil {
result.Error = fmt.Errorf("drive upload: %w", err)
return result