much better
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
|
||||
"dirmd/internal/config"
|
||||
)
|
||||
|
||||
type State int
|
||||
@@ -39,6 +41,7 @@ type Model struct {
|
||||
isDark bool
|
||||
width int
|
||||
height int
|
||||
command string
|
||||
}
|
||||
|
||||
func New() Model {
|
||||
@@ -79,6 +82,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.form.SetError(err.Error())
|
||||
return m, nil
|
||||
}
|
||||
m.command = buildCommand(cfg)
|
||||
m.state = StateGenerating
|
||||
return m, func() tea.Msg {
|
||||
return genResultMsg{result: Generate(cfg)}
|
||||
@@ -114,6 +118,70 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func buildCommand(cfg *config.Config) string {
|
||||
var parts []string
|
||||
parts = append(parts, "dirmd")
|
||||
|
||||
parts = append(parts, "-o", cfg.OutputPath)
|
||||
|
||||
if cfg.AppendMode {
|
||||
parts = append(parts, "-a")
|
||||
}
|
||||
if cfg.Force {
|
||||
parts = append(parts, "-f")
|
||||
}
|
||||
if cfg.VerticalSlices {
|
||||
parts = append(parts, "--vertical-slices")
|
||||
}
|
||||
if cfg.SkipFrontend {
|
||||
parts = append(parts, "--skip-frontend")
|
||||
}
|
||||
if cfg.FrontendOnly {
|
||||
parts = append(parts, "--frontend-only")
|
||||
}
|
||||
if cfg.OmitTest {
|
||||
parts = append(parts, "--omit-test")
|
||||
}
|
||||
if cfg.OmitMd {
|
||||
parts = append(parts, "--omit-md")
|
||||
}
|
||||
if cfg.ProtonDrive {
|
||||
parts = append(parts, "--proton-drive")
|
||||
if cfg.DrivePath != "" {
|
||||
parts = append(parts, "--drive-path", cfg.DrivePath)
|
||||
}
|
||||
}
|
||||
if cfg.MaxDepth != 20 {
|
||||
parts = append(parts, "--max-depth", fmt.Sprintf("%d", cfg.MaxDepth))
|
||||
}
|
||||
if cfg.MaxSize != 512*1024 {
|
||||
parts = append(parts, "--max-size", fmt.Sprintf("%d", cfg.MaxSize))
|
||||
}
|
||||
|
||||
extraIgnores := extraIgnores(cfg)
|
||||
for _, ig := range extraIgnores {
|
||||
parts = append(parts, "--ignore", ig)
|
||||
}
|
||||
|
||||
parts = append(parts, cfg.InputPath)
|
||||
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
func extraIgnores(cfg *config.Config) []string {
|
||||
defaultSet := make(map[string]bool)
|
||||
for _, d := range config.DefaultIgnores {
|
||||
defaultSet[d] = true
|
||||
}
|
||||
var extra []string
|
||||
for _, ig := range cfg.Ignores {
|
||||
if !defaultSet[ig] {
|
||||
extra = append(extra, ig)
|
||||
}
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
func (m Model) View() tea.View {
|
||||
var content string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user