using Spectre.Console; using ZB.MOM.WW.Secrets.Cli.Interactive.Flows; namespace ZB.MOM.WW.Secrets.Cli.Interactive; /// /// Composition root for the interactive console: the non-TTY gate that decides whether a bare /// secret invocation launches the console, and the default wiring (flow set, recents store, /// target reader, session factory) that hands to an . /// public static class InteractiveEntry { /// /// Whether a bare secret invocation should launch the interactive console. True only when no /// verb was supplied AND neither standard stream is redirected — a redirected stdin/stdout means the /// invocation is scripted/piped, where the console's prompts would hang or corrupt the pipe, so the /// caller falls through to headless usage instead. /// /// The process command-line arguments. /// at process start. /// at process start. public static bool ShouldEnterInteractive(string[] args, bool inputRedirected, bool outputRedirected) => args.Length == 0 && !inputRedirected && !outputRedirected; /// /// Builds the ordered flow set the shell is wired with — one instance of each menu action, in the /// order they appear on the menu. Exposed (and used by ) so the composition /// is assertable without running the shell. /// public static IReadOnlyList CreateFlows() => [ new ListSecretsFlow(), new SetSecretFlow(), new RevealSecretFlow(), new DeleteSecretFlow(), new ReferenceAuditFlow(), new KekDoctorFlow(), new BundleExportFlow(), new BundleImportFlow(), ]; /// /// Wires an with its default collaborators: a per-user recents store /// under ~/.zb-secrets/recent-targets.json, the target-config reader, the session factory, and /// . The shell's own ctor re-validates flow-title uniqueness. /// /// The console surface the shell (and its flows) render to. public static InteractiveShell CreateShell(IAnsiConsole console) { string recentsPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".zb-secrets", "recent-targets.json"); return new InteractiveShell( console, new RecentTargetsStore(recentsPath), new TargetConfigReader(), new SecretsSessionFactory(), CreateFlows()); } }