remove append#
This commit is contained in:
+14
-14
@@ -2,6 +2,8 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/textarea"
|
||||
@@ -15,7 +17,6 @@ import (
|
||||
const (
|
||||
fieldInputDir = iota
|
||||
fieldOutputDir
|
||||
fieldAppend
|
||||
fieldForce
|
||||
fieldVerticalSlices
|
||||
fieldSkipFrontend
|
||||
@@ -40,7 +41,6 @@ type FormModel struct {
|
||||
maxDepth textinput.Model
|
||||
maxSize textinput.Model
|
||||
ignoreArea textarea.Model
|
||||
appendMode Checkbox
|
||||
force Checkbox
|
||||
verticalSlices Checkbox
|
||||
skipFrontend Checkbox
|
||||
@@ -54,15 +54,25 @@ type FormModel struct {
|
||||
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 {
|
||||
inputDir := textinput.New()
|
||||
inputDir.Placeholder = "."
|
||||
inputDir.SetValue(".")
|
||||
inputDir.SetWidth(60)
|
||||
|
||||
defOut := defaultOutputDir()
|
||||
outputDir := textinput.New()
|
||||
outputDir.Placeholder = "./output_dirmd"
|
||||
outputDir.SetValue("./output_dirmd")
|
||||
outputDir.Placeholder = defOut
|
||||
outputDir.SetValue(defOut)
|
||||
outputDir.SetWidth(60)
|
||||
|
||||
drivePath := textinput.New()
|
||||
@@ -90,7 +100,6 @@ func NewForm() FormModel {
|
||||
maxDepth: maxDepth,
|
||||
maxSize: maxSize,
|
||||
ignoreArea: ignoreArea,
|
||||
appendMode: Checkbox{Label: "Append to existing file"},
|
||||
force: Checkbox{Label: "Force overwrite"},
|
||||
verticalSlices: Checkbox{Label: "Vertical slices"},
|
||||
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...)
|
||||
case isActivate(k):
|
||||
switch m.focusIndex {
|
||||
case fieldAppend:
|
||||
m.appendMode.Toggle()
|
||||
case fieldForce:
|
||||
m.force.Toggle()
|
||||
case fieldVerticalSlices:
|
||||
@@ -317,8 +324,6 @@ func (m FormModel) View() string {
|
||||
b.WriteString(m.renderTextField("Output directory", m.outputDir, m.focusIndex == fieldOutputDir))
|
||||
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("\n")
|
||||
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")
|
||||
}
|
||||
|
||||
if m.appendMode.Checked && m.verticalSlices.Checked {
|
||||
return nil, fmt.Errorf("--append and --vertical-slices are mutually exclusive")
|
||||
}
|
||||
|
||||
excludedExts := append([]string{}, config.DefaultExts...)
|
||||
if m.skipFrontend.Checked {
|
||||
excludedExts = append(excludedExts, config.FrontendExts...)
|
||||
@@ -443,7 +444,6 @@ func (m FormModel) ToConfig() (*config.Config, error) {
|
||||
cfg := &config.Config{
|
||||
InputPath: inputDir,
|
||||
OutputPath: outputDir,
|
||||
AppendMode: m.appendMode.Checked,
|
||||
Force: m.force.Checked,
|
||||
MaxSize: int64(maxSizeKB) * 1024,
|
||||
MaxDepth: maxDepth,
|
||||
|
||||
+24
-55
@@ -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
|
||||
|
||||
@@ -124,9 +124,6 @@ func buildCommand(cfg *config.Config) string {
|
||||
|
||||
parts = append(parts, "-o", cfg.OutputPath)
|
||||
|
||||
if cfg.AppendMode {
|
||||
parts = append(parts, "-a")
|
||||
}
|
||||
if cfg.Force {
|
||||
parts = append(parts, "-f")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user