(ctx *snap.Context)
| 20 | } |
| 21 | |
| 22 | func 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 | |
| 61 | func resolveTaskfilePath(ctx *snap.Context) (string, error) { |
| 62 | var fileFlag string |
no test coverage detected