Skip to content

Commit

Permalink
Implement command
Browse files Browse the repository at this point in the history
  • Loading branch information
unkaktus committed Jul 4, 2024
1 parent c49ce47 commit 162d388
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cmd/robin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ func run() (err error) {
return nil
},
},
{
Name: "show",
Usage: "show the job data",
Flags: []cli.Flag{},
Action: func(cCtx *cli.Context) error {
if bs == nil {
return errUnsupported
}
jobName := cCtx.Args().Get(0)

if err := robin.Show(bs, jobName); err != nil {
return fmt.Errorf("show error: %w", err)
}

return nil
},
},
},
}
return app.Run(os.Args)
Expand Down
2 changes: 1 addition & 1 deletion logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Logs(b BatchSystem, jobName string, outputType string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("execute tail: %w", err)
return fmt.Errorf("execute editor: %w", err)
}

return nil
Expand Down
38 changes: 38 additions & 0 deletions show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package robin

import (
"fmt"
"os"
"os/exec"
)

func Show(b BatchSystem, jobName string) error {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vim"
}

job, err := findJob(b, jobName)
if err != nil {
return fmt.Errorf("find job: %w", err)
}

comment := &Comment{}
if err := comment.Decode(job.Comment); err != nil {
return fmt.Errorf("decode comment: %w", err)
}

if comment.JobDataFilename == "" {
return fmt.Errorf("no job data file")
}

cmd := exec.Command(editor, comment.JobDataFilename)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("execute editor: %w", err)
}

return nil
}

0 comments on commit 162d388

Please sign in to comment.