Skip to content

Commit 7b255f2

Browse files
committed
refactor: mega refactoring in progress
1 parent dcd98b3 commit 7b255f2

32 files changed

Lines changed: 877 additions & 3273 deletions

Runfile.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ tasks:
1616
example:
1717
dir: ./examples
1818
cmd:
19-
- |+
20-
run cook clean
19+
- echo "hello world"
2120

2221
test:old:
2322
cmd:

cmd/run/completions.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package main
22

3-
import (
4-
"context"
5-
"fmt"
6-
"io"
7-
"log/slog"
3+
//
4+
// import (
5+
// "context"
6+
// "fmt"
7+
// "io"
8+
// "log/slog"
9+
//
10+
// "github.com/nxtcoder17/fastlog"
11+
// "github.com/nxtcoder17/runfile/pkg/runfile"
12+
// )
813

9-
"github.com/nxtcoder17/fastlog"
10-
"github.com/nxtcoder17/runfile/pkg/runfile"
11-
)
12-
13-
func generateShellCompletion(ctx context.Context, writer io.Writer, rfpath string) error {
14-
runfile, err := runfile.ParseFromFile(runfile.NewContext(ctx, fastlog.New()), rfpath)
15-
if err != nil {
16-
slog.Error("parsing, got", "err", err)
17-
panic(err)
18-
}
19-
20-
for k := range runfile.Tasks {
21-
fmt.Fprintf(writer, "%s\n", k)
22-
}
23-
24-
return nil
25-
}
14+
// func generateShellCompletion(ctx context.Context, writer io.Writer, rfpath string) error {
15+
// runfile, err := runfile.ParseFromFile(runfile.NewContext(ctx, fastlog.New()), rfpath)
16+
// if err != nil {
17+
// slog.Error("parsing, got", "err", err)
18+
// panic(err)
19+
// }
20+
//
21+
// for k := range runfile.Tasks {
22+
// fmt.Fprintf(writer, "%s\n", k)
23+
// }
24+
//
25+
// return nil
26+
// }

cmd/run/completions/run.fish

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
# args: (1)
2-
# run fish shell completion
3-
set PROGNAME run
4-
5-
# list_targets fetches all targets, with all flags provided on the cli
6-
function list_targets
7-
# eval $PROGNAME --list
8-
eval (commandline -b) --list
1+
# # args: (1)
2+
# # run fish shell completion
3+
# set PROGNAME run
4+
#
5+
# # list_targets fetches all targets, with all flags provided on the cli
6+
# function list_targets
7+
# # eval $PROGNAME --list
8+
# eval (commandline -b) --list
9+
# echo "shell:completion"
10+
# end
11+
#
12+
# complete -c $PROGNAME -d "runs named task" -xa '(list_targets)'
13+
# complete -c $PROGNAME -d "runs named task" -xa '(list_targets)'
14+
# complete -c $PROGNAME -l help -s h -d 'show help'
15+
# complete -c $PROGNAME -l list -s l -d 'list all tasks'
16+
# complete -c $PROGNAME -rF -l file -s f -d 'runs targets from this runfile'
17+
18+
# completion fish shell completion
19+
20+
function __fish_completion_no_subcommand --description 'Test if there has been any subcommand yet'
21+
for i in (commandline -opc)
22+
if contains -- $i
23+
return 1
24+
end
25+
end
26+
return 0
927
end
1028

11-
complete -c $PROGNAME -d "runs named task" -xa '(list_targets)'
12-
complete -c $PROGNAME -l help -s h -d 'show help'
13-
complete -c $PROGNAME -l list -s l -d 'list all tasks'
14-
complete -c $PROGNAME -rF -l file -s f -d 'runs targets from this runfile'
29+
complete -c completion -n '__fish_completion_no_subcommand' -f -l help -s h -d 'show help'
30+
complete -c completion -n '__fish_completion_no_subcommand' -f -l help -s h -d 'show help'
1531

cmd/run/main.go

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,26 @@ func main() {
9595
return
9696
}
9797

98-
runfilePath, err := locateRunfile(c)
99-
if err != nil {
100-
slog.Error("locating runfile", "err", err)
101-
panic(err)
102-
}
98+
// runfilePath, err := locateRunfile(c)
99+
// if err != nil {
100+
// slog.Error("locating runfile", "err", err)
101+
// panic(err)
102+
// }
103103

104-
generateShellCompletion(ctx, c.Root().Writer, runfilePath)
104+
// generateShellCompletion(ctx, c.Root().Writer, runfilePath)
105105
},
106106

107107
Commands: []*cli.Command{
108108
{
109-
Name: "shell:completion",
110-
Usage: "<bash|zsh|fish|ps>",
111-
Suggest: true,
109+
Name: "shell:completion",
110+
Usage: "[shell]",
111+
EnableShellCompletion: false,
112112
Action: func(ctx context.Context, c *cli.Command) error {
113-
fmt.Printf("args: (%d)\n", c.NArg())
114-
if c.NArg() != 1 {
115-
return fmt.Errorf("needs argument one of [bash,zsh,fish,ps]")
113+
if c.NArg() == 0 {
114+
for _, shell := range []string{"fish", "bash", "zsh", "powershell"} {
115+
fmt.Fprintf(c.Writer, "%s\n", shell)
116+
}
117+
return nil
116118
}
117119

118120
switch c.Args().First() {
@@ -139,12 +141,12 @@ func main() {
139141

140142
showList := c.Bool("list")
141143
if showList {
142-
runfilePath, err := locateRunfile(c)
143-
if err != nil {
144-
slog.Error("locating runfile, got", "err", err)
145-
return err
146-
}
147-
return generateShellCompletion(ctx, c.Root().Writer, runfilePath)
144+
// runfilePath, err := locateRunfile(c)
145+
// if err != nil {
146+
// slog.Error("locating runfile, got", "err", err)
147+
// return err
148+
// }
149+
// return generateShellCompletion(ctx, c.Root().Writer, runfilePath)
148150
}
149151

150152
if c.NArg() == 0 {
@@ -185,37 +187,20 @@ func main() {
185187
return fmt.Errorf("parallel and watch can't be set together")
186188
}
187189

188-
logger := fastlog.New(fastlog.Options{
189-
Format: fastlog.ConsoleFormat,
190-
EnableColors: true,
191-
ShowCaller: debug,
192-
ShowTimestamp: false,
193-
ShowDebugLogs: debug,
194-
})
190+
logger := fastlog.New(fastlog.Console(), fastlog.ShowDebugLogs(debug), fastlog.WithoutTimestamp())
195191

196192
runfilePath, err := locateRunfile(c)
197193
if err != nil {
198194
slog.Error("locating runfile, got", "err", err)
199195
return err
200196
}
201197

202-
rctx := runfile.NewContext(ctx, logger)
203-
204-
rf, err := runfile.ParseFromFile(rctx, runfilePath)
205-
if err != nil {
206-
slog.Error("parsing runfile, got", "err", err)
207-
panic(err)
208-
}
209-
210-
if err := rf.Run(rctx, args, runfile.RunOption{
211-
ExecuteInParallel: parallel,
212-
Watch: watch,
213-
Debug: debug,
214-
KVs: kv,
215-
}); err != nil {
198+
if err := runfile.RunTask(ctx, runfilePath, args[0]); err != nil {
199+
logger.Error("ERRORED", "err", err)
216200
if err2, ok := err.(*errors.Error); ok {
217201
logger.Error(err2.Error(), err2.SlogAttrs()...)
218202
}
203+
return err
219204
}
220205

221206
return nil

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ require (
99
github.com/charmbracelet/lipgloss v1.0.0
1010
github.com/joho/godotenv v1.5.1
1111
github.com/muesli/termenv v0.15.2
12-
github.com/nxtcoder17/fastlog v0.0.0-20250702035423-1739653a5c24
12+
github.com/nxtcoder17/fastlog v0.0.0-20251112144402-5324a708e570
1313
github.com/nxtcoder17/fwatcher v1.2.2-0.20250804201159-543ad31be162
14+
github.com/stretchr/testify v1.9.0
1415
github.com/urfave/cli/v3 v3.0.0-beta1
1516
golang.org/x/sync v0.10.0
1617
golang.org/x/term v0.32.0
@@ -20,6 +21,7 @@ require (
2021
require (
2122
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2223
github.com/charmbracelet/x/ansi v0.4.2 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
2325
github.com/dlclark/regexp2 v1.11.4 // indirect
2426
github.com/fsnotify/fsnotify v1.8.0 // indirect
2527
github.com/google/go-cmp v0.6.0 // indirect
@@ -28,11 +30,13 @@ require (
2830
github.com/mattn/go-isatty v0.0.20 // indirect
2931
github.com/mattn/go-runewidth v0.0.16 // indirect
3032
github.com/nxtcoder17/go.pkgs v0.0.0-20250216034729-39e2d2cd48da // indirect
33+
github.com/pmezard/go-difflib v1.0.0 // indirect
3134
github.com/rivo/uniseg v0.4.7 // indirect
3235
github.com/rs/zerolog v1.33.0 // indirect
3336
github.com/samber/lo v1.47.0 // indirect
3437
github.com/samber/slog-common v0.18.1 // indirect
3538
github.com/samber/slog-zerolog/v2 v2.7.3 // indirect
3639
golang.org/x/sys v0.33.0 // indirect
3740
golang.org/x/text v0.16.0 // indirect
41+
gopkg.in/yaml.v3 v3.0.1 // indirect
3842
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
3939
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
4040
github.com/nxtcoder17/fastlog v0.0.0-20250702035423-1739653a5c24 h1:oLLpFv1p7jRRrrsZzyf77pECLAMKrTxzHRSoHNRoELw=
4141
github.com/nxtcoder17/fastlog v0.0.0-20250702035423-1739653a5c24/go.mod h1:x6o+8WEHRGaWu9XEhSdTrjmDjKhVnKNXd/XZ56bNN/o=
42+
github.com/nxtcoder17/fastlog v0.0.0-20251112144402-5324a708e570 h1:uiafpAq+4R/W7QcDJ8GiM7feWHBuojrekKNxiX+POis=
43+
github.com/nxtcoder17/fastlog v0.0.0-20251112144402-5324a708e570/go.mod h1:x6o+8WEHRGaWu9XEhSdTrjmDjKhVnKNXd/XZ56bNN/o=
4244
github.com/nxtcoder17/fwatcher v1.2.2-0.20250804201159-543ad31be162 h1:7EHTiBm6MVUMzT8pdeavpXcxwzzIbDC0QJwre6OvGAk=
4345
github.com/nxtcoder17/fwatcher v1.2.2-0.20250804201159-543ad31be162/go.mod h1:SMwIdCpyi5fBygrkCX8hIIUeILzgoxJFaDSlhFBOWWQ=
4446
github.com/nxtcoder17/go.pkgs v0.0.0-20250216034729-39e2d2cd48da h1:Y6GILHFlrihVfDqDPQ98y2kdUeI0SQc8tnoXh2NbEIA=

nixy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
nixpkgs:
2-
default: 554be6495561ff07b6c724047bdd7e0716aa7b46
2+
default: 554be6495561ff07b6c724047bdd7e0716aa7b46
3+
34
packages:
45
- go
56
- pre-commit

pkg/errors/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ func ErrTaskInvalidCommand(command any, err error) *Error {
6767
func ErrInvalidShellAlias(alias string) *Error {
6868
return WrapStr("invalid shell alias").KV("alias", alias)
6969
}
70+
71+
func ErrCircularDependency(taskName string) *Error {
72+
return WrapStr("circular dependency detected").KV("task", taskName)
73+
}

pkg/errors/errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func (e *Error) SlogAttrs() []any {
7575
return result
7676
}
7777

78+
func (e *Error) Wrap(err error) *Error {
79+
e.err = errors.Join(e.err, err)
80+
return e
81+
}
82+
7883
func WrapErr(err error) *Error {
7984
return &Error{
8085
err: err,
@@ -96,3 +101,7 @@ func WrapStr(v string) *Error {
96101
func New(msg string) *Error {
97102
return WrapStr(msg)
98103
}
104+
105+
// func Wrap(msg string, err ...error) *Error {
106+
// return errors.Join(errors.New(msg), errors.Join(err...))
107+
// }

pkg/runfile/parse-command.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)