@@ -64,11 +64,7 @@ private static Command CreateInstallCommand()
6464 // Support comma-separated packages: "pkg1,pkg2,pkg3" becomes ["pkg1", "pkg2", "pkg3"]
6565 var packages = rawPackages ?
6666 . SelectMany ( p => p . Split ( ',' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) )
67- . ToArray ( ) ;
68-
69- var formatter = useJson
70- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
71- : new SpectreOutputFormatter ( ) ;
67+ . ToArray ( ) ; var formatter = Program . GetFormatter ( context ) ;
7268
7369 try
7470 {
@@ -227,9 +223,7 @@ private static Command CreateJdkCommand()
227223 var jdkManager = Program . JdkManager ;
228224
229225 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
230- var formatter = useJson
231- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
232- : new SpectreOutputFormatter ( ) ;
226+ var formatter = Program . GetFormatter ( context ) ;
233227
234228 var healthCheck = await jdkManager . CheckHealthAsync ( context . GetCancellationToken ( ) ) ;
235229
@@ -263,11 +257,7 @@ private static Command CreateJdkCommand()
263257 var version = context . ParseResult . GetValueForOption (
264258 ( Option < int > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "version" ) ) ;
265259 var path = context . ParseResult . GetValueForOption (
266- ( Option < string > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "path" ) ) ;
267-
268- var formatter = useJson
269- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
270- : new SpectreOutputFormatter ( ) ;
260+ ( Option < string > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "path" ) ) ; var formatter = Program . GetFormatter ( context ) ;
271261
272262 try
273263 {
@@ -307,12 +297,12 @@ private static Command CreateJdkCommand()
307297
308298 if ( useJson )
309299 {
310- var formatter = new JsonOutputFormatter ( Console . Out ) ;
300+ var formatter = Program . GetFormatter ( context ) ;
311301 formatter . Write ( new { versions = versions } ) ;
312302 }
313303 else
314304 {
315- var formatter = new SpectreOutputFormatter ( ) ;
305+ var formatter = Program . GetFormatter ( context ) ;
316306 formatter . WriteTable (
317307 versions ,
318308 ( "Version" , v => v . ToString ( ) ) ,
@@ -338,9 +328,7 @@ private static Command CreateSdkCommand()
338328 var androidProvider = Program . AndroidProvider ;
339329
340330 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
341- var formatter = useJson
342- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
343- : new SpectreOutputFormatter ( ) ;
331+ var formatter = Program . GetFormatter ( context ) ;
344332
345333 var checks = await androidProvider . CheckHealthAsync ( context . GetCancellationToken ( ) ) ;
346334 var sdkCheck = checks . FirstOrDefault ( c => c . Name == "Android SDK" ) ;
@@ -377,11 +365,7 @@ private static Command CreateSdkCommand()
377365
378366 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
379367 var dryRun = context . ParseResult . GetValueForOption ( GlobalOptions . DryRunOption ) ;
380- var packages = context . ParseResult . GetValueForArgument ( sdkInstallPkgsArg ) ;
381-
382- var formatter = useJson
383- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
384- : new SpectreOutputFormatter ( ) ;
368+ var packages = context . ParseResult . GetValueForArgument ( sdkInstallPkgsArg ) ; var formatter = Program . GetFormatter ( context ) ;
385369
386370 try
387371 {
@@ -581,11 +565,7 @@ await spectreInstall.Console.Status()
581565 var showAvailable = context . ParseResult . GetValueForOption (
582566 ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "available" ) ) ;
583567 var showAll = context . ParseResult . GetValueForOption (
584- ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "all" ) ) ;
585-
586- var formatter = useJson
587- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
588- : new SpectreOutputFormatter ( ) ;
568+ ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "all" ) ) ; var formatter = Program . GetFormatter ( context ) ;
589569
590570 try
591571 {
@@ -701,9 +681,7 @@ void WriteGroupedPackages(IEnumerable<SdkPackage> pkgs, string title)
701681 var androidProvider = Program . AndroidProvider ;
702682
703683 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
704- var formatter = useJson
705- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
706- : new SpectreOutputFormatter ( ) ;
684+ var formatter = Program . GetFormatter ( context ) ;
707685
708686 try
709687 {
@@ -830,11 +808,7 @@ private static Command CreateSdkUninstallCommand()
830808 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
831809 var dryRun = context . ParseResult . GetValueForOption ( GlobalOptions . DryRunOption ) ;
832810 var packages = context . ParseResult . GetValueForArgument (
833- ( Argument < string [ ] > ) context . ParseResult . CommandResult . Command . Arguments . First ( ) ) ;
834-
835- var formatter = useJson
836- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
837- : new SpectreOutputFormatter ( ) ;
811+ ( Argument < string [ ] > ) context . ParseResult . CommandResult . Command . Arguments . First ( ) ) ; var formatter = Program . GetFormatter ( context ) ;
838812
839813 try
840814 {
@@ -876,9 +850,7 @@ private static Command CreateEmulatorCommand()
876850 var androidProvider = Program . AndroidProvider ;
877851
878852 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
879- var formatter = useJson
880- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
881- : new SpectreOutputFormatter ( ) ;
853+ var formatter = Program . GetFormatter ( context ) ;
882854
883855 try
884856 {
@@ -933,11 +905,7 @@ private static Command CreateEmulatorCommand()
933905 var device = context . ParseResult . GetValueForOption (
934906 ( Option < string > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "device" ) ) ;
935907 var force = context . ParseResult . GetValueForOption (
936- ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "force" ) ) ;
937-
938- var formatter = useJson
939- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
940- : new SpectreOutputFormatter ( ) ;
908+ ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "force" ) ) ; var formatter = Program . GetFormatter ( context ) ;
941909
942910 try
943911 {
@@ -1081,11 +1049,7 @@ private static Command CreateEmulatorCommand()
10811049 var coldBoot = context . ParseResult . GetValueForOption (
10821050 ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "cold-boot" ) ) ;
10831051 var wait = context . ParseResult . GetValueForOption (
1084- ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "wait" ) ) ;
1085-
1086- var formatter = useJson
1087- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
1088- : new SpectreOutputFormatter ( ) ;
1052+ ( Option < bool > ) context . ParseResult . CommandResult . Command . Options . First ( o => o . Name == "wait" ) ) ; var formatter = Program . GetFormatter ( context ) ;
10891053
10901054 try
10911055 {
@@ -1174,11 +1138,7 @@ await spectre.StatusAsync($"Starting {name}...", async () =>
11741138
11751139 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
11761140 var dryRun = context . ParseResult . GetValueForOption ( GlobalOptions . DryRunOption ) ;
1177- var name = context . ParseResult . GetValueForArgument ( stopNameArg ) ;
1178-
1179- var formatter = useJson
1180- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
1181- : new SpectreOutputFormatter ( ) ;
1141+ var name = context . ParseResult . GetValueForArgument ( stopNameArg ) ; var formatter = Program . GetFormatter ( context ) ;
11821142
11831143 try
11841144 {
@@ -1289,11 +1249,7 @@ await spectreStop2.StatusAsync($"Stopping {name}...", async () =>
12891249
12901250 var useJson = context . ParseResult . GetValueForOption ( GlobalOptions . JsonOption ) ;
12911251 var dryRun = context . ParseResult . GetValueForOption ( GlobalOptions . DryRunOption ) ;
1292- var name = context . ParseResult . GetValueForArgument ( deleteNameArg ) ;
1293-
1294- var formatter = useJson
1295- ? ( IOutputFormatter ) new JsonOutputFormatter ( Console . Out )
1296- : new SpectreOutputFormatter ( ) ;
1252+ var name = context . ParseResult . GetValueForArgument ( deleteNameArg ) ; var formatter = Program . GetFormatter ( context ) ;
12971253
12981254 try
12991255 {
0 commit comments