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
+14 -14
View File
@@ -2,6 +2,8 @@ package tui
import ( import (
"fmt" "fmt"
"os"
"path/filepath"
"strings" "strings"
"charm.land/bubbles/v2/textarea" "charm.land/bubbles/v2/textarea"
@@ -15,7 +17,6 @@ import (
const ( const (
fieldInputDir = iota fieldInputDir = iota
fieldOutputDir fieldOutputDir
fieldAppend
fieldForce fieldForce
fieldVerticalSlices fieldVerticalSlices
fieldSkipFrontend fieldSkipFrontend
@@ -40,7 +41,6 @@ type FormModel struct {
maxDepth textinput.Model maxDepth textinput.Model
maxSize textinput.Model maxSize textinput.Model
ignoreArea textarea.Model ignoreArea textarea.Model
appendMode Checkbox
force Checkbox force Checkbox
verticalSlices Checkbox verticalSlices Checkbox
skipFrontend Checkbox skipFrontend Checkbox
@@ -54,15 +54,25 @@ type FormModel struct {
err string err string
} }
func defaultOutputDir() string {
cwd, err := os.Getwd()
if err != nil {
return "/tmp/output_dirmd"
}
base := filepath.Base(cwd)
return filepath.Join("/tmp", base+"_dirmd")
}
func NewForm() FormModel { func NewForm() FormModel {
inputDir := textinput.New() inputDir := textinput.New()
inputDir.Placeholder = "." inputDir.Placeholder = "."
inputDir.SetValue(".") inputDir.SetValue(".")
inputDir.SetWidth(60) inputDir.SetWidth(60)
defOut := defaultOutputDir()
outputDir := textinput.New() outputDir := textinput.New()
outputDir.Placeholder = "./output_dirmd" outputDir.Placeholder = defOut
outputDir.SetValue("./output_dirmd") outputDir.SetValue(defOut)
outputDir.SetWidth(60) outputDir.SetWidth(60)
drivePath := textinput.New() drivePath := textinput.New()
@@ -90,7 +100,6 @@ func NewForm() FormModel {
maxDepth: maxDepth, maxDepth: maxDepth,
maxSize: maxSize, maxSize: maxSize,
ignoreArea: ignoreArea, ignoreArea: ignoreArea,
appendMode: Checkbox{Label: "Append to existing file"},
force: Checkbox{Label: "Force overwrite"}, force: Checkbox{Label: "Force overwrite"},
verticalSlices: Checkbox{Label: "Vertical slices"}, verticalSlices: Checkbox{Label: "Vertical slices"},
skipFrontend: Checkbox{Label: "Skip frontend files"}, skipFrontend: Checkbox{Label: "Skip frontend files"},
@@ -238,8 +247,6 @@ func (m FormModel) Update(msg tea.Msg) (FormModel, tea.Cmd) {
return m, tea.Batch(cmds...) return m, tea.Batch(cmds...)
case isActivate(k): case isActivate(k):
switch m.focusIndex { switch m.focusIndex {
case fieldAppend:
m.appendMode.Toggle()
case fieldForce: case fieldForce:
m.force.Toggle() m.force.Toggle()
case fieldVerticalSlices: case fieldVerticalSlices:
@@ -317,8 +324,6 @@ func (m FormModel) View() string {
b.WriteString(m.renderTextField("Output directory", m.outputDir, m.focusIndex == fieldOutputDir)) b.WriteString(m.renderTextField("Output directory", m.outputDir, m.focusIndex == fieldOutputDir))
b.WriteString("\n\n") b.WriteString("\n\n")
b.WriteString(m.appendMode.Render(m.focusIndex == fieldAppend))
b.WriteString("\n")
b.WriteString(m.force.Render(m.focusIndex == fieldForce)) b.WriteString(m.force.Render(m.focusIndex == fieldForce))
b.WriteString("\n") b.WriteString("\n")
b.WriteString(m.verticalSlices.Render(m.focusIndex == fieldVerticalSlices)) b.WriteString(m.verticalSlices.Render(m.focusIndex == fieldVerticalSlices))
@@ -428,10 +433,6 @@ func (m FormModel) ToConfig() (*config.Config, error) {
return nil, fmt.Errorf("--skip-frontend and --frontend-only are mutually exclusive") return nil, fmt.Errorf("--skip-frontend and --frontend-only are mutually exclusive")
} }
if m.appendMode.Checked && m.verticalSlices.Checked {
return nil, fmt.Errorf("--append and --vertical-slices are mutually exclusive")
}
excludedExts := append([]string{}, config.DefaultExts...) excludedExts := append([]string{}, config.DefaultExts...)
if m.skipFrontend.Checked { if m.skipFrontend.Checked {
excludedExts = append(excludedExts, config.FrontendExts...) excludedExts = append(excludedExts, config.FrontendExts...)
@@ -443,7 +444,6 @@ func (m FormModel) ToConfig() (*config.Config, error) {
cfg := &config.Config{ cfg := &config.Config{
InputPath: inputDir, InputPath: inputDir,
OutputPath: outputDir, OutputPath: outputDir,
AppendMode: m.appendMode.Checked,
Force: m.force.Checked, Force: m.force.Checked,
MaxSize: int64(maxSizeKB) * 1024, MaxSize: int64(maxSizeKB) * 1024,
MaxDepth: maxDepth, MaxDepth: maxDepth,
+6 -37
View File
@@ -27,30 +27,6 @@ func Generate(cfg *config.Config) GenerateResult {
} }
cfg.AbsRoot = abs 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) absOutput, err := filepath.Abs(cfg.OutputPath)
if err != nil { if err != nil {
result.Error = fmt.Errorf("resolve output path: %w", err) result.Error = fmt.Errorf("resolve output path: %w", err)
@@ -62,6 +38,8 @@ func Generate(cfg *config.Config) GenerateResult {
result.Error = fmt.Errorf("output %s exists and is not a directory (enable force)", absOutput) result.Error = fmt.Errorf("output %s exists and is not a directory (enable force)", absOutput)
return result return result
} }
result.Error = fmt.Errorf("output %s exists (enable force)", absOutput)
return result
} }
if err := os.MkdirAll(absOutput, 0755); err != nil { if err := os.MkdirAll(absOutput, 0755); err != nil {
@@ -70,8 +48,6 @@ func Generate(cfg *config.Config) GenerateResult {
} }
cfg.OutputPath = absOutput cfg.OutputPath = absOutput
outputDir = absOutput
}
walkResult, err := walker.Run(cfg) walkResult, err := walker.Run(cfg)
if err != nil { if err != nil {
@@ -94,12 +70,8 @@ func Generate(cfg *config.Config) GenerateResult {
} }
result.Files = generated result.Files = generated
} else { } else {
indexPath := cfg.OutputPath indexPath := filepath.Join(cfg.OutputPath, "index_"+repoName+".md")
if !cfg.AppendMode && !cfg.SingleFile { if err := renderer.Write(walkResult, indexPath, false, false); err != nil {
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
}
if err := renderer.Write(walkResult, indexPath, cfg.AppendMode, cfg.SingleFile); err != nil {
result.Error = err result.Error = err
return result return result
} }
@@ -109,7 +81,7 @@ func Generate(cfg *config.Config) GenerateResult {
if cfg.ProtonDrive { if cfg.ProtonDrive {
remoteDir := cfg.DrivePath remoteDir := cfg.DrivePath
if remoteDir == "" { if remoteDir == "" {
remoteDir = "/my-files/md/" + filepath.Base(outputDir) remoteDir = "/my-files/md/" + filepath.Base(cfg.OutputPath)
} }
if err := drive.CheckAuth(); err != nil { if err := drive.CheckAuth(); err != nil {
@@ -123,10 +95,7 @@ func Generate(cfg *config.Config) GenerateResult {
return result return result
} }
} else { } else {
indexPath := cfg.OutputPath indexPath := filepath.Join(cfg.OutputPath, "index_"+repoName+".md")
if !cfg.AppendMode && !cfg.SingleFile {
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
}
if err := drive.Upload(indexPath, remoteDir); err != nil { if err := drive.Upload(indexPath, remoteDir); err != nil {
result.Error = fmt.Errorf("drive upload: %w", err) result.Error = fmt.Errorf("drive upload: %w", err)
return result return result
-3
View File
@@ -124,9 +124,6 @@ func buildCommand(cfg *config.Config) string {
parts = append(parts, "-o", cfg.OutputPath) parts = append(parts, "-o", cfg.OutputPath)
if cfg.AppendMode {
parts = append(parts, "-a")
}
if cfg.Force { if cfg.Force {
parts = append(parts, "-f") parts = append(parts, "-f")
} }