MCPcopy Create free account
hub / github.com/driangle/taskmd / runNextID

Function runNextID

apps/cli/internal/cli/nextid.go:41–82  ·  view source on GitHub ↗
(_ *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

39}
40
41func runNextID(_ *cobra.Command, args []string) error {
42 flags := GetGlobalFlags()
43
44 scanDir := ResolveScanDir(args)
45
46 taskScanner := scanner.NewScanner(scanDir, flags.Verbose, flags.IgnoreDirs)
47 result, err := taskScanner.Scan()
48 if err != nil {
49 return fmt.Errorf("scan failed: %w", err)
50 }
51
52 if flags.Verbose && len(result.Errors) > 0 {
53 fmt.Fprintf(os.Stderr, "\nWarning: encountered %d errors during scan:\n", len(result.Errors))
54 for _, scanErr := range result.Errors {
55 fmt.Fprintf(os.Stderr, " %s: %v\n", scanErr.FilePath, scanErr.Error)
56 }
57 fmt.Fprintln(os.Stderr)
58 }
59
60 warnDuplicateIDs(result.Tasks)
61
62 ids := make([]string, len(result.Tasks))
63 for i, task := range result.Tasks {
64 ids[i] = task.ID
65 }
66
67 cfg := resolveIDConfig()
68
69 switch nextIDFormat {
70 case "plain":
71 id, genErr := generateID(ids, cfg)
72 if genErr != nil {
73 return genErr
74 }
75 fmt.Println(id)
76 return nil
77 case "json":
78 return outputNextIDJSON(ids, cfg)
79 default:
80 return ValidateFormat(nextIDFormat, []string{"plain", "json"})
81 }
82}
83
84func outputNextIDJSON(ids []string, cfg validator.IDConfig) error {
85 switch cfg.Strategy {

Callers 6

TestNextID_NumericIDsFunction · 0.85
TestNextID_PrefixedIDsFunction · 0.85
TestNextID_JSONFormatFunction · 0.85
TestNextID_PlainFormatFunction · 0.85

Calls 8

ScanMethod · 0.95
GetGlobalFlagsFunction · 0.85
ResolveScanDirFunction · 0.85
warnDuplicateIDsFunction · 0.85
resolveIDConfigFunction · 0.85
generateIDFunction · 0.85
outputNextIDJSONFunction · 0.85
ValidateFormatFunction · 0.85

Tested by 6

TestNextID_NumericIDsFunction · 0.68
TestNextID_PrefixedIDsFunction · 0.68
TestNextID_JSONFormatFunction · 0.68
TestNextID_PlainFormatFunction · 0.68