MCPcopy Index your code
hub / github.com/nikivdev/go / tasksCmd

Function tasksCmd

tasks.go:22–59  ·  view source on GitHub ↗
(ctx *snap.Context)

Source from the content-addressed store, hash-verified

20}
21
22func tasksCmd(ctx *snap.Context) error {
23 taskfilePath, err := resolveTaskfilePath(ctx)
24 if err != nil {
25 return err
26 }
27
28 content, err := os.ReadFile(taskfilePath)
29 if err != nil {
30 return fmt.Errorf("read %s: %w", taskfilePath, err)
31 }
32
33 var tf taskfile
34 if err := yaml.Unmarshal(content, &tf); err != nil {
35 return fmt.Errorf("parse %s: %w", taskfilePath, err)
36 }
37
38 names := make([]string, 0, len(tf.Tasks))
39 for name := range tf.Tasks {
40 names = append(names, name)
41 }
42 sort.Strings(names)
43
44 fmt.Fprintf(ctx.Stdout(), "Tasks from %s:\n", taskfilePath)
45 if len(names) == 0 {
46 fmt.Fprintln(ctx.Stdout(), " (none)")
47 return nil
48 }
49
50 for _, name := range names {
51 desc := strings.TrimSpace(tf.Tasks[name].Desc)
52 if desc == "" {
53 desc = "(no description)"
54 }
55 fmt.Fprintf(ctx.Stdout(), " %s: %s\n", name, desc)
56 }
57
58 return nil
59}
60
61func resolveTaskfilePath(ctx *snap.Context) (string, error) {
62 var fileFlag string

Callers 1

mainFunction · 0.85

Calls 1

resolveTaskfilePathFunction · 0.85

Tested by

no test coverage detected