()
| 60 | } |
| 61 | |
| 62 | func cmdInit() { |
| 63 | fs := flag.NewFlagSet("init", flag.ExitOnError) |
| 64 | force := fs.Bool("force", false, "recreate master key if exists") |
| 65 | mode := fs.String("mode", "", "authentication mode: touchid or otp (empty = interactive prompt)") |
| 66 | seedTTL := fs.Int("seed-unlock-ttl", 3600, "OTP seed cache time (seconds), OTP mode only") |
| 67 | algorithm := fs.String("algorithm", "SHA1", "TOTP algorithm: SHA1, SHA256, SHA512, OTP mode only") |
| 68 | digits := fs.Int("digits", 6, "TOTP digits: 6 or 8, OTP mode only") |
| 69 | interactive := fs.Bool("interactive", false, "run full setup wizard") |
| 70 | nonInteractive := fs.Bool("non-interactive", false, "disable all interactive prompts") |
| 71 | fs.Parse(os.Args[2:]) |
| 72 | |
| 73 | // Decide whether to run interactive mode |
| 74 | isTTY := term.IsTerminal(int(os.Stdin.Fd())) |
| 75 | shouldRunInteractive := *interactive || (isTTY && *mode == "" && !*nonInteractive) |
| 76 | |
| 77 | if shouldRunInteractive { |
| 78 | runInteractiveSetup(*force, *seedTTL, *algorithm, *digits) |
| 79 | } else { |
| 80 | runLegacyInit(*force, *mode, *seedTTL, *algorithm, *digits) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // runLegacyInit executes the original non-interactive initialization |
| 85 | func runLegacyInit(force bool, mode string, seedTTL int, algorithm string, digits int) { |
no test coverage detected