summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--completion/completion.go12
-rw-r--r--main.go10
-rw-r--r--modes.go14
-rw-r--r--run/edit.go2
-rw-r--r--spool/exit.go8
-rw-r--r--spool/spool.go2
6 files changed, 24 insertions, 24 deletions
diff --git a/completion/completion.go b/completion/completion.go
index 6fa6814..89252ba 100644
--- a/completion/completion.go
+++ b/completion/completion.go
@@ -39,22 +39,22 @@ func Add(shell string) *spool.ExitCode {
f := filepath.Join(paths.HomeDir.String(), completionFileByShell[shell])
content, err := os.ReadFile(f)
if err != nil {
- return &spool.FatalReadFailure
+ return spool.FatalReadFailure
}
if strings.Contains(string(content), strings.TrimSpace(completionCodeByShell[shell])) {
- return &spool.CompletionAlreadyInstalledFailure
+ return spool.CompletionAlreadyInstalledFailure
}
fd, err := os.OpenFile(f, os.O_APPEND|os.O_WRONLY, 0600)
defer fd.Close()
if err != nil {
- return &spool.FatalReadFailure
+ return spool.FatalReadFailure
}
_, err = fd.Write([]byte(fmt.Sprintf(completionFormat, completionComment, completionCodeByShell[shell])))
if err != nil {
- return &spool.CompletionFailure
+ return spool.CompletionFailure
}
successMessage(shell, f)
- return &spool.Success
+ return spool.Success
}
func successMessage(shell string, file string) {
@@ -65,5 +65,5 @@ func successMessage(shell string, file string) {
// because it is baked in with the program it should always be version-appropriate
func Echo() *spool.ExitCode {
_, _ = spool.Print("%s", completionCode)
- return &spool.Success
+ return spool.Success
}
diff --git a/main.go b/main.go
index 7e229fe..f7060bd 100644
--- a/main.go
+++ b/main.go
@@ -95,7 +95,7 @@ func mode[T any](list ModeMap[T], fire func(mode T) *spool.ExitCode) *spool.Exit
return nil
}
-func pik() spool.ExitCode {
+func pik() *spool.ExitCode {
// initialize the flags outside the main method so it can re-run in case
// pik changes its own configuration at runtime
@@ -106,14 +106,14 @@ func pik() spool.ExitCode {
return mode()
})
if code != nil {
- return *code
+ return code
}
code = mode(statelessModes, func(mode func() *spool.ExitCode) *spool.ExitCode {
return mode()
})
if code != nil {
- return *code
+ return code
}
syncInitializers.RunSync(func(initializer model.Initializer) error {
@@ -177,7 +177,7 @@ func pik() spool.ExitCode {
return mode(st)
})
if code != nil {
- return *code
+ return code
}
args := pflag.Args()
@@ -240,7 +240,7 @@ func pik() spool.ExitCode {
return mode(st, result.Source, result.Target)
})
if code != nil {
- return *code
+ return code
}
err = run.Run(result.Source, result.Target, result.Args...)
diff --git a/modes.go b/modes.go
index ec1f465..deb1509 100644
--- a/modes.go
+++ b/modes.go
@@ -45,14 +45,14 @@ var profileFd *os.File
var uninitializedModes = ModeMap[func() *spool.ExitCode]{
flags.Version: func() *spool.ExitCode {
_, _ = spool.Print("%s\n", version)
- return &spool.Success
+ return spool.Success
},
flags.Completion: func() *spool.ExitCode {
return completion.Echo()
},
flags.Help: func() *spool.ExitCode {
_ = manview.View(help)
- return &spool.Success
+ return spool.Success
},
}
@@ -62,7 +62,7 @@ var statelessModes = ModeMap[func() *spool.ExitCode]{
flags.InstallCompletion: func() *spool.ExitCode {
sh := os.Getenv("SHELL")
if sh == "" {
- return &spool.UnknownShellFailure
+ return spool.UnknownShellFailure
}
_, sh = filepath.Split(sh)
return completion.Add(sh)
@@ -70,12 +70,12 @@ var statelessModes = ModeMap[func() *spool.ExitCode]{
flags.Profile: func() *spool.ExitCode {
fd, err := os.Create("pik-profile.out")
if err != nil {
- return &spool.ProfilingFailure
+ return spool.ProfilingFailure
}
runtime.SetCPUProfileRate(1000)
err = pprof.StartCPUProfile(profileFd)
if err != nil {
- return &spool.ProfilingFailure
+ return spool.ProfilingFailure
}
profileFd = fd
return nil
@@ -96,9 +96,9 @@ var statefulModes = ModeMap[func(st *model.State) *spool.ExitCode]{
}
if count == 0 {
- return &spool.NoTargetsFailure
+ return spool.NoTargetsFailure
}
- return &spool.Success
+ return spool.Success
},
}
diff --git a/run/edit.go b/run/edit.go
index 804218a..47e04e7 100644
--- a/run/edit.go
+++ b/run/edit.go
@@ -13,7 +13,7 @@ var NoEditorError = errors.New("$EDITOR not set")
func Edit(t model.Target, src *model.Source) *spool.ExitCode {
editor := os.Getenv("EDITOR")
if editor == "" {
- return &spool.NoEditorFailure
+ return spool.NoEditorFailure
}
cmd := exec.Command(editor, t.File(src))
cmd.Stdin = os.Stdin
diff --git a/spool/exit.go b/spool/exit.go
index 23cf9da..77bff44 100644
--- a/spool/exit.go
+++ b/spool/exit.go
@@ -35,7 +35,7 @@ var (
var Codes []ExitCode
var CodeMap = make(map[int]*ExitCode)
-func New(num int, message string) ExitCode {
+func New(num int, message string) *ExitCode {
if CodeMap[num] != nil && num != 0 {
_, _ = Warn("redefined error code: %v", num)
}
@@ -45,14 +45,14 @@ func New(num int, message string) ExitCode {
}
Codes = append(Codes, c)
CodeMap[num] = &c
- return c
+ return &c
}
-func (e ExitCode) Exit() {
+func (e *ExitCode) Exit() {
os.Exit(e.Value)
}
-func (e ExitCode) Next(message string) ExitCode {
+func (e *ExitCode) Next(message string) *ExitCode {
return New(
e.Value+1,
message,
diff --git a/spool/spool.go b/spool/spool.go
index 4335d50..ce02dc5 100644
--- a/spool/spool.go
+++ b/spool/spool.go
@@ -25,7 +25,7 @@ var Warn = func(format string, values ...any) (any, error) {
return fmt.Fprintf(Stderr, format, values...)
}
-var Panic = func(code ExitCode, format string, values ...any) (any, error) {
+var Panic = func(code *ExitCode, format string, values ...any) (any, error) {
pkg := reflect.TypeOf(empty{}).PkgPath()
v, err := fmt.Fprintf(Stderr, format, values...)
st := strings.Split(string(debug.Stack()), "\n")