From f6963b1c451afcb2f0d0104f38178235e52f8b63 Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 14 Apr 2026 20:13:13 +0200 Subject: remove all name repetition --- runner/gnumake/make.go | 2 +- runner/gnumake/target.go | 20 +++++++++--------- runner/just/just.go | 2 +- runner/just/target.go | 18 ++++++++-------- runner/python/file.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ runner/python/filetarget.go | 51 --------------------------------------------- runner/python/indexer.go | 4 ++-- runner/python/proj.go | 49 +++++++++++++++++++++++++++++++++++++++++++ runner/python/projtarget.go | 49 ------------------------------------------- runner/python/runner.go | 4 ++-- runner/shell/hydrated.go | 8 +++---- runner/shell/shell.go | 6 +++--- runner/shell/target.go | 12 +++++------ 13 files changed, 138 insertions(+), 138 deletions(-) create mode 100644 runner/python/file.go delete mode 100644 runner/python/filetarget.go create mode 100644 runner/python/proj.go delete mode 100644 runner/python/projtarget.go (limited to 'runner') diff --git a/runner/gnumake/make.go b/runner/gnumake/make.go index 3d84edc..e36a2b0 100644 --- a/runner/gnumake/make.go +++ b/runner/gnumake/make.go @@ -68,7 +68,7 @@ func ParseOutput(input string) []model.Target { name := split[0] name = strings.TrimSpace(name) name = strings.TrimSuffix(name, ":") - tgt := &MakeTarget{ + tgt := &Target{ BaseTarget: runner.BaseTarget{ Identity: identity.New(name), MyTags: nil, diff --git a/runner/gnumake/target.go b/runner/gnumake/target.go index 8d6f91c..2f909bb 100644 --- a/runner/gnumake/target.go +++ b/runner/gnumake/target.go @@ -6,13 +6,13 @@ import ( "pik/runner" ) -type MakeTarget struct { +type Target struct { runner.BaseTarget Name string Description string } -func (j *MakeTarget) Create(s *model.Source) *exec.Cmd { +func (j *Target) Create(s *model.Source) *exec.Cmd { return exec.Command(Indexer.path, j.Identity.Full) } @@ -20,28 +20,28 @@ var makeSub = []string{ "make", } -func (j *MakeTarget) Sub() []string { +func (j *Target) Sub() []string { return makeSub } -func (j *MakeTarget) Label() string { +func (j *Target) Label() string { return j.Identity.Full } -func (j *MakeTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { - return &HydratedJustTarget{ +func (j *Target) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &Hydrated{ BaseHydration: runner.Hydrated(j), }, nil } -type HydratedJustTarget struct { - runner.BaseHydration[*MakeTarget] +type Hydrated struct { + runner.BaseHydration[*Target] } -func (h *HydratedJustTarget) Icon() string { +func (h *Hydrated) Icon() string { return "\uE673" } -func (h *HydratedJustTarget) Description() string { +func (h *Hydrated) Description() string { return h.BaseTarget.Description } diff --git a/runner/just/just.go b/runner/just/just.go index a800212..7d6bb92 100644 --- a/runner/just/just.go +++ b/runner/just/just.go @@ -73,7 +73,7 @@ func ParseOutput(input string) []model.Target { var result []model.Target for c, targets := range categories { for _, t := range targets { - result = append(result, &JustTarget{ + result = append(result, &Target{ BaseTarget: runner.BaseTarget{ Identity: identity.New(t), }, diff --git a/runner/just/target.go b/runner/just/target.go index c36e4af..ca33b6b 100644 --- a/runner/just/target.go +++ b/runner/just/target.go @@ -6,36 +6,36 @@ import ( "pik/runner" ) -type JustTarget struct { +type Target struct { runner.BaseTarget Category string } -func (j JustTarget) Create(s *model.Source) *exec.Cmd { +func (j Target) Create(s *model.Source) *exec.Cmd { return exec.Command(Indexer.path, j.Identity.Full) } -func (j JustTarget) Sub() []string { +func (j Target) Sub() []string { if j.Category != "" { return []string{j.Category} } return nil } -func (j JustTarget) Label() string { +func (j Target) Label() string { return j.Identity.Full } -func (j *JustTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { - return &HydratedJustTarget{ +func (j *Target) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &Hydrated{ BaseHydration: runner.Hydrated(j), }, nil } -type HydratedJustTarget struct { - runner.BaseHydration[*JustTarget] +type Hydrated struct { + runner.BaseHydration[*Target] } -func (h *HydratedJustTarget) Icon() string { +func (h *Hydrated) Icon() string { return "\uF039" } diff --git a/runner/python/file.go b/runner/python/file.go new file mode 100644 index 0000000..f8b6c2e --- /dev/null +++ b/runner/python/file.go @@ -0,0 +1,51 @@ +package python + +import ( + "os/exec" + "path/filepath" + "pik/model" + "pik/runner" +) + +type File struct { + runner.BaseTarget + File string +} + +type HydratedFileTarget struct { + runner.BaseHydration[*File] +} + +func (h *HydratedFileTarget) Icon() string { + return "\uE606" +} + +func (p *File) Create(s *model.Source) *exec.Cmd { + var cmd []string + if Python.Uv != "" { + cmd = []string{Python.Uv, "run", "--", p.File} + } else if venv := Python.VenvFor(s); venv != "" { + cmd = []string{filepath.Join(s.Path, venv, "bin", "python3"), p.File} + } else { + sysPath, err := exec.LookPath("python3") + if err != nil { + return nil + } + cmd = []string{sysPath, p.File} + } + return exec.Command(cmd[0], cmd[1:]...) +} + +func (p *File) Sub() []string { + return nil +} + +func (p *File) Label() string { + return p.Full +} + +func (p *File) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &HydratedFileTarget{ + BaseHydration: runner.Hydrated(p), + }, nil +} diff --git a/runner/python/filetarget.go b/runner/python/filetarget.go deleted file mode 100644 index 6793f4b..0000000 --- a/runner/python/filetarget.go +++ /dev/null @@ -1,51 +0,0 @@ -package python - -import ( - "os/exec" - "path/filepath" - "pik/model" - "pik/runner" -) - -type FileTarget struct { - runner.BaseTarget - File string -} - -type HydratedFileTarget struct { - runner.BaseHydration[*FileTarget] -} - -func (h *HydratedFileTarget) Icon() string { - return "\uE606" -} - -func (p *FileTarget) Create(s *model.Source) *exec.Cmd { - var cmd []string - if Python.Uv != "" { - cmd = []string{Python.Uv, "run", "--", p.File} - } else if venv := Python.VenvFor(s); venv != "" { - cmd = []string{filepath.Join(s.Path, venv, "bin", "python3"), p.File} - } else { - sysPath, err := exec.LookPath("python3") - if err != nil { - return nil - } - cmd = []string{sysPath, p.File} - } - return exec.Command(cmd[0], cmd[1:]...) -} - -func (p *FileTarget) Sub() []string { - return nil -} - -func (p *FileTarget) Label() string { - return p.Full -} - -func (p *FileTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { - return &HydratedFileTarget{ - BaseHydration: runner.Hydrated(p), - }, nil -} diff --git a/runner/python/indexer.go b/runner/python/indexer.go index d0dd4e3..3a61f7e 100644 --- a/runner/python/indexer.go +++ b/runner/python/indexer.go @@ -8,7 +8,7 @@ import ( "pik/model" ) -type Pyproj struct { +type pyproj struct { Project struct { Scripts map[string]string } @@ -29,7 +29,7 @@ func (p python) Index(path string, f fs.FS, runners []model.Runner) ([]model.Tar return nil, err } - pp := &Pyproj{} + pp := &pyproj{} err = toml.Unmarshal(content, pp) if err != nil { diff --git a/runner/python/proj.go b/runner/python/proj.go new file mode 100644 index 0000000..9a711bd --- /dev/null +++ b/runner/python/proj.go @@ -0,0 +1,49 @@ +package python + +import ( + "os/exec" + "path/filepath" + "pik/model" + "pik/runner" +) + +type Project struct { + runner.BaseTarget + Cmd string +} + +type Hydrated struct { + runner.BaseHydration[*Project] +} + +func (h *Hydrated) Icon() string { + return "\uE606" +} + +func (h *Hydrated) Description() string { + return h.BaseTarget.Cmd +} + +func (p *Project) Create(s *model.Source) *exec.Cmd { + var cmd []string + if Python.Uv != "" { + cmd = []string{Python.Uv, "run", "--", p.Cmd} + } else if venv := Python.VenvFor(s); venv != "" { + cmd = []string{filepath.Join(s.Path, venv, "bin", "python"), p.Cmd} + } + return exec.Command(cmd[0], cmd[1:]...) +} + +func (p *Project) Sub() []string { + return nil +} + +func (p *Project) Label() string { + return p.Cmd +} + +func (p *Project) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &Hydrated{ + BaseHydration: runner.Hydrated(p), + }, nil +} diff --git a/runner/python/projtarget.go b/runner/python/projtarget.go deleted file mode 100644 index c7422b4..0000000 --- a/runner/python/projtarget.go +++ /dev/null @@ -1,49 +0,0 @@ -package python - -import ( - "os/exec" - "path/filepath" - "pik/model" - "pik/runner" -) - -type ProjTarget struct { - runner.BaseTarget - Cmd string -} - -type HydratedProjTarget struct { - runner.BaseHydration[*ProjTarget] -} - -func (h *HydratedProjTarget) Icon() string { - return "\uE606" -} - -func (h *HydratedProjTarget) Description() string { - return h.BaseTarget.Cmd -} - -func (p *ProjTarget) Create(s *model.Source) *exec.Cmd { - var cmd []string - if Python.Uv != "" { - cmd = []string{Python.Uv, "run", "--", p.Cmd} - } else if venv := Python.VenvFor(s); venv != "" { - cmd = []string{filepath.Join(s.Path, venv, "bin", "python"), p.Cmd} - } - return exec.Command(cmd[0], cmd[1:]...) -} - -func (p *ProjTarget) Sub() []string { - return nil -} - -func (p *ProjTarget) Label() string { - return p.Cmd -} - -func (p *ProjTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { - return &HydratedProjTarget{ - BaseHydration: runner.Hydrated(p), - }, nil -} diff --git a/runner/python/runner.go b/runner/python/runner.go index b06d8ab..2293336 100644 --- a/runner/python/runner.go +++ b/runner/python/runner.go @@ -57,7 +57,7 @@ func (p python) PyFor(src *model.Source) []string { } func (p python) CreateProjTarget(name string, cmd string) model.Target { - return &ProjTarget{ + return &Project{ BaseTarget: runner.BaseTarget{ Identity: identity.New(name), }, @@ -67,7 +67,7 @@ func (p python) CreateProjTarget(name string, cmd string) model.Target { func (p python) CreateTarget(fs fs.FS, source string, file string, entry fs.DirEntry) (model.Target, error) { _, filename := filepath.Split(file) - return &FileTarget{ + return &File{ BaseTarget: runner.BaseTarget{ Identity: identity.New(filename), MyTags: model.TagsFromFilename(filename), diff --git a/runner/shell/hydrated.go b/runner/shell/hydrated.go index 77fc45c..e1f8892 100644 --- a/runner/shell/hydrated.go +++ b/runner/shell/hydrated.go @@ -6,15 +6,15 @@ import ( "pik/spool" ) -type HydratedShellTarget struct { - runner.BaseHydration[*ShellTarget] +type Hydrated struct { + runner.BaseHydration[*Target] } -func (h *HydratedShellTarget) Icon() string { +func (h *Hydrated) Icon() string { return "\uF489" } -func (h *HydratedShellTarget) Description() string { +func (h *Hydrated) Description() string { desc, err := describe.Describe(h.BaseTarget.Script) if err != nil { spool.Warn("%v\n", err) diff --git a/runner/shell/shell.go b/runner/shell/shell.go index 5333279..9d34e0f 100644 --- a/runner/shell/shell.go +++ b/runner/shell/shell.go @@ -38,11 +38,11 @@ type shell struct { var WrongTargetError = errors.New("wrong target type") func (s *shell) Hydrate(target model.Target) (model.HydratedTarget, error) { - cast, ok := target.(*ShellTarget) + cast, ok := target.(*Target) if !ok { return nil, WrongTargetError } - hyd := &HydratedShellTarget{BaseHydration: runner.Hydrated(cast)} + hyd := &Hydrated{BaseHydration: runner.Hydrated(cast)} return hyd, nil } @@ -102,7 +102,7 @@ func (s *shell) CreateTarget(fs fs.FS, src string, file string, _ fs.DirEntry) ( } sub = append(sub, p) } - return &ShellTarget{ + return &Target{ BaseTarget: runner.BaseTarget{ Identity: identity.New(filename), MyTags: model.TagsFromFilename(filename), diff --git a/runner/shell/target.go b/runner/shell/target.go index e823d41..db3fcc8 100644 --- a/runner/shell/target.go +++ b/runner/shell/target.go @@ -7,29 +7,29 @@ import ( "pik/runner" ) -type ShellTarget struct { +type Target struct { runner.BaseTarget Shell string Script string SubValue []string } -func (s *ShellTarget) String() string { +func (s *Target) String() string { return s.Label() } -func (s *ShellTarget) Hydrate(_ *model.Source) (model.HydratedTarget, error) { +func (s *Target) Hydrate(_ *model.Source) (model.HydratedTarget, error) { return Runner.Hydrate(s) } -func (s *ShellTarget) Sub() []string { +func (s *Target) Sub() []string { return s.SubValue } -func (s *ShellTarget) Label() string { +func (s *Target) Label() string { return s.Identity.Full } -func (s *ShellTarget) Create(src *model.Source) *exec.Cmd { +func (s *Target) Create(src *model.Source) *exec.Cmd { return exec.Command(s.Shell, filepath.Join(src.Path, s.Script)) } -- cgit v1.3