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

Function resolveInitIDStrategy

apps/cli/internal/cli/project_init.go:362–398  ·  view source on GitHub ↗

resolveInitIDStrategy returns the ID strategy config. If --id-strategy was provided, uses it. If TTY, prompts. Otherwise defaults to sequential.

(cmd *cobra.Command, isTTY bool)

Source from the content-addressed store, hash-verified

360// resolveInitIDStrategy returns the ID strategy config.
361// If --id-strategy was provided, uses it. If TTY, prompts. Otherwise defaults to sequential.
362func resolveInitIDStrategy(cmd *cobra.Command, isTTY bool) (idStrategyConfig, error) {
363 cfg := idStrategyConfig{strategy: "sequential"}
364
365 if cmd.Flags().Changed("id-strategy") {
366 if !isValidIDStrategy(projectInitIDStrategy) {
367 return cfg, fmt.Errorf("invalid --id-strategy %q: must be one of %s",
368 projectInitIDStrategy, strings.Join(validIDStrategies, ", "))
369 }
370 cfg.strategy = projectInitIDStrategy
371 if cfg.strategy == "prefixed" {
372 prefix, err := resolveIDPrefix(cmd, isTTY)
373 if err != nil {
374 return cfg, err
375 }
376 cfg.prefix = prefix
377 }
378 return cfg, nil
379 }
380
381 if isTTY {
382 strategy, err := promptIDStrategy()
383 if err != nil {
384 return cfg, err
385 }
386 cfg.strategy = strategy
387 if cfg.strategy == "prefixed" {
388 prefix, err := resolveIDPrefix(cmd, isTTY)
389 if err != nil {
390 return cfg, err
391 }
392 cfg.prefix = prefix
393 }
394 return cfg, nil
395 }
396
397 return cfg, nil
398}
399
400func isValidIDStrategy(s string) bool {
401 for _, v := range validIDStrategies {

Callers 1

runProjectInitFunction · 0.85

Calls 3

isValidIDStrategyFunction · 0.85
resolveIDPrefixFunction · 0.85
promptIDStrategyFunction · 0.85

Tested by

no test coverage detected