2626import java .util .List ;
2727import java .util .Optional ;
2828import java .util .function .Supplier ;
29+ import java .util .stream .Collectors ;
30+ import java .util .stream .Stream ;
2931
3032import static com .dtsx .astra .cli .core .output .ExitCode .INVALID_TOKEN ;
3133import static com .dtsx .astra .cli .core .output .ExitCode .UNSUPPORTED_EXECUTION ;
@@ -155,6 +157,14 @@ protected Operation<SetupResult> mkOperation() {
155157 }
156158
157159 private void assertShouldSetup (Path existing ) {
160+ assertShouldSetup (existing , true );
161+ }
162+
163+ private void assertShouldContinueIfAlreadySetup (Path existing ) {
164+ assertShouldSetup (existing , false );
165+ }
166+
167+ private void assertShouldSetup (Path path , boolean newUser ) {
158168 ctx .log ().banner ();
159169
160170 if (ctx .isNotTty ()) {
@@ -170,57 +180,39 @@ private void assertShouldSetup(Path existing) {
170180 }
171181
172182 val prompt = """
173- @|bold Welcome to the Astra CLI setup!|@
174-
175- @|faint A configuration file with your profile will be created at|@ @|faint,italic %s|@
183+ @|bold Welcome to the interactive Astra CLI setup!|@
176184
177- If you'd prefer to provide credentials on a per-command basis rather than storing them in a file, you can either:
178- - Use the per-command @'!--token!@ flag to pass your existing @!AstraCS!@ token directly.
179- - Use the per-command @'!--config-file!@ flag to specify an existing @!.astrarc!@ file.
180-
181- %s
182- %s
185+ @|faint Your configuration file %s at|@ @|faint,italic %s|@
183186 """ .formatted (
184- existing ,
185- renderComment (ctx .colors (), "Example:" ),
186- renderCommand (ctx .colors (), "${cli.name} db list --token <your_token>" )
187+ (newUser ) ? "will be created" : "already exists" ,
188+ path
187189 );
188190
189- ctx .console ().println (trimIndent (prompt ));
191+ val addendum = (!newUser )
192+ ? NL + NL + "Do you want to continue and create a new profile?"
193+ : mkArgsAddendum ();
194+
195+ ctx .console ().println (trimIndent (prompt ) + addendum );
190196 ctx .console ().println ();
191197 ctx .console ().unsafeReadLine (ctx .colors ().format ("Press @!Enter!@ to continue, or use @!Ctrl+C!@ to cancel. " ), false );
192198 ctx .console ().println ();
193199 }
194200
195- private void assertShouldContinueIfAlreadySetup (Path existing ) {
196- ctx .log ().banner ();
201+ private String mkArgsAddendum () {
202+ if ($env .isEmpty () && $token .isEmpty ()) {
203+ if ($name .isPresent ()) {
204+ return "%n%n@|faint The profile will be called '%s'.|@" .formatted ($name .get ());
205+ }
206+ return "" ;
207+ }
197208
198- val prompt = """
199- @|bold Looks like you're already set up!|@
200-
201- @|faint Your config file already exists at|@ @|faint,italic %s|@
202-
203- Hint: You can use the @'!${cli.name} config!@ commands to manage your profiles.
204-
205- %s
206- %s
207-
208- Do you want to continue and create a new profile?
209- """ .formatted (
210- existing ,
211- renderComment (ctx .colors (), "Example:" ),
212- renderCommand (ctx .colors (), "${cli.name} config list" )
209+ return "%n%n@|faint %s will be created%s.|@" .formatted (
210+ $name .map (n -> "Profile '" + n + "'" ).orElse ("The profile" ),
211+ Stream .concat (
212+ $token .stream ().map (t -> " with token " + t ),
213+ $env .stream ().map (e -> " in env '" + e .name ().toLowerCase () + "'" )
214+ ).collect (Collectors .joining ("" ))
213215 );
214-
215- val shouldContinue = ctx .console ().confirm (prompt )
216- .defaultYes ()
217- .fallbackFlag ("" )
218- .fix (List .of (), "" )
219- .clearAfterSelection ();
220-
221- if (!shouldContinue ) {
222- throw new ExecutionCancelledException ();
223- }
224216 }
225217
226218 private void assertShouldOverwriteExistingProfile (Profile existing ) {
0 commit comments