sdkman-cli-native 0.5.2

Native CLI subcommand components for SDKMAN! written in Rust. Use the binaries generated by this project in the sdk wrapper shell function from the sdkman-cli project.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
extern crate clap;

use clap::Command;
use colored::Colorize;
use textwrap::{fill, indent};

fn main() {
    let default_error = format!(
        "error: no subcommand specified (use {} for help)",
        "sdk help".italic()
    );
    let args = Command::new("help")
        .override_help(default_error)
        .subcommand(Command::new("config"))
        .subcommand(Command::new("current").alias("c"))
        .subcommand(Command::new("default").alias("d"))
        .subcommand(Command::new("env").alias("e"))
        .subcommand(Command::new("flush"))
        .subcommand(Command::new("home").alias("h"))
        .subcommand(Command::new("install").alias("i"))
        .subcommand(Command::new("list").alias("ls"))
        .subcommand(Command::new("selfupdate"))
        .subcommand(Command::new("uninstall").alias("rm"))
        .subcommand(Command::new("update"))
        .subcommand(Command::new("upgrade"))
        .subcommand(Command::new("use").alias("u"))
        .subcommand(Command::new("version").alias("v"))
        .get_matches();

    let help = match args.subcommand_name() {
        Some("config") => config_help(),
        Some("current") => current_help(),
        Some("default") => default_help(),
        Some("env") => env_help(),
        Some("flush") => flush_help(),
        Some("home") => home_help(),
        Some("install") => install_help(),
        Some("list") => list_help(),
        Some("selfupdate") => selfupdate_help(),
        Some("uninstall") => uninstall_help(),
        Some("update") => update_help(),
        Some("upgrade") => upgrade_help(),
        Some("use") => use_help(),
        Some("version") => version_help(),
        _ => main_help(),
    };

    println!("{}", &render(help));
}

struct Subcommand {
    command: String,
    description: String,
}

struct Configuration {
    content: String,
    snippet: String,
}

struct Mnemonic {
    shorthand: String,
    command: String,
}

#[derive(Default)]
struct Help {
    cmd: String,
    tagline: String,
    synopsis: String,
    description: String,
    subcommands: Option<Vec<Subcommand>>,
    configuration: Option<Configuration>,
    mnemonic: Option<Mnemonic>,
    exit_code: Option<String>,
    examples: String,
}

const INDENTATION_WIDTH: usize = 4;
const TERMINAL_WIDTH: usize = 80;
const TEXT_WIDTH: usize = TERMINAL_WIDTH - INDENTATION_WIDTH;

fn render(help: Help) -> String {
    let spaced_tab = format!("{:width$}", " ", width = INDENTATION_WIDTH);
    let indentation = spaced_tab.as_str();
    let nameline = format!("{} - {}", help.cmd.italic(), help.tagline);
    let wrapped_nameline = fill(&nameline, TEXT_WIDTH);
    let name = format!(
        "\n{}\n{}\n\n",
        "NAME".bold(),
        indent(&wrapped_nameline, indentation)
    );

    let synopsis = format!(
        "{}\n{}\n\n",
        "SYNOPSIS".bold(),
        indent(&format!("{}", help.synopsis.italic()), indentation)
    );

    let description = format!(
        "{}\n{}\n\n",
        "DESCRIPTION".bold(),
        indent(&fill(help.description.as_str(), TEXT_WIDTH), indentation)
    );

    let subcommands: String = help
        .subcommands
        .iter()
        .map(|subs| {
            let lines: String = subs
                .iter()
                .map(|sub| {
                    let desc_depth = 17;
                    let desc_indent = format!("{:width$}", " ", width = desc_depth);
                    let command = indent(&fill(&sub.command, desc_depth), indentation);
                    let description = &indent(
                        &fill(&sub.description, TEXT_WIDTH - desc_depth),
                        &desc_indent,
                    )[command.len()..];
                    format!("{}{}\n", command.to_string(), description)
                })
                .collect();
            return format!("{}\n{}\n", "SUBCOMMANDS & QUALIFIERS".bold(), lines);
        })
        .collect();

    let configuration = help
        .configuration
        .map(|config| {
            format!(
                "{}\n{}\n\n{}\n\n",
                "CONFIGURATION".bold(),
                indent(&fill(&config.content, TEXT_WIDTH), indentation),
                indent(&config.snippet, indentation)
            )
        })
        .unwrap_or_else(|| String::new());

    let mnemonic = help
        .mnemonic
        .map(|mnemonic| {
            let text = format!(
                "{} - may be used in place of the {} subcommand.",
                &mnemonic.shorthand.bold(),
                &mnemonic.command.bold()
            );
            format!("{}\n{}\n\n", "MNEMONIC".bold(), indent(&text, indentation))
        })
        .unwrap_or_else(|| String::new());

    let exit_code = help
        .exit_code
        .map(|m| {
            format!(
                "{}\n{}\n\n",
                "EXIT CODE".bold(),
                indent(&fill(&m, TEXT_WIDTH), indentation)
            )
        })
        .unwrap_or_else(|| String::new());

    let examples = format!(
        "{}\n{}\n\n",
        "EXAMPLES".bold(),
        indent(&format!("{}", help.examples.italic()), indentation)
    );

    format!(
        "{}{}{}{}{}{}{}{}",
        name, synopsis, description, subcommands, configuration, exit_code, mnemonic, examples
    )
}

fn main_help() -> Help {
    Help {
        cmd: "sdk".to_string(),
        tagline: "The command line interface (CLI) for SDKMAN!".to_string(),
        synopsis: "sdk <subcommand> [candidate] [version]".to_string(),
        description: "SDKMAN! is a tool for managing parallel versions of multiple JVM related Software Development \
        Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, \
        switching, removing and listing Candidates.".to_string(),
        subcommands: Some(vec![
            Subcommand { command: "help".to_string(), description: "[subcommand]".italic().to_string() },
            Subcommand { command: "install".to_string(), description: "<candidate> [version] [path]".italic().to_string() },
            Subcommand { command: "uninstall".to_string(), description: "<candidate> <version>".italic().to_string() },
            Subcommand { command: "list".to_string(), description: "[candidate]".italic().to_string() },
            Subcommand { command: "use".to_string(), description: "<candidate> <version>".italic().to_string() },
            Subcommand { command: "config".to_string(), description: "no qualifier".to_string() },
            Subcommand { command: "default".to_string(), description: "<candidate> [version]".italic().to_string() },
            Subcommand { command: "home".to_string(), description: "<candidate> <version>".italic().to_string() },
            Subcommand { command: "env".to_string(), description: "[init|install|clear]".italic().to_string() },
            Subcommand { command: "current".to_string(), description: "[candidate]".italic().to_string() },
            Subcommand { command: "upgrade".to_string(), description: "[candidate]".italic().to_string() },
            Subcommand { command: "version".to_string(), description: "no qualifier".to_string() },
            Subcommand { command: "offline".to_string(), description: "[enable|disable]".italic().to_string() },
            Subcommand { command: "selfupdate".to_string(), description: "[force]".italic().to_string() },
            Subcommand { command: "update".to_string(), description: "no qualifier".to_string() },
            Subcommand { command: "flush".to_string(), description: "[tmp|metadata|version]".italic().to_string() },
        ]),
        examples: "sdk install java 17.0.0-tem\nsdk help install".to_string(),
        ..Default::default()
    }
}

fn config_help() -> Help {
    let config_file = "${SDKMAN_DIR}/etc/config";
    let default_config = "\
---
sdkman_auto_answer=false
sdkman_auto_complete=true
sdkman_auto_env=false
sdkman_auto_update=true
sdkman_beta_channel=false
sdkman_checksum_enable=true
sdkman_colour_enable=true
sdkman_curl_connect_timeout=7
sdkman_curl_max_time=10
sdkman_debug_mode=false
sdkman_insecure_ssl=false
sdkman_selfupdate_feature=true
---";
    Help {
        cmd: "sdk config".to_string(),
        tagline: "sdk subcommand to edit the SDKMAN configuration file".to_string(),
        synopsis: "sdk config".to_string(),
        description: format!("This subcommand opens a text editor on the configuration file located at {}. \
        The subcommand will infer the text editor from the {} environment variable. If the system does \
        not set the {} environment variable, then vi is assumed as the default editor.", config_file.underline(),
                             "EDITOR".italic(), "EDITOR".italic()),
        configuration: Some(
            Configuration {
                content: format!("The {} file contains the following default configuration. A new shell should be \
                opened for any configuration changes to take effect.", config_file.underline()),
                snippet: default_config.italic().to_string(),
            }
        ),
        examples: "sdk config".to_string(),
        ..Default::default()
    }
}

fn current_help() -> Help {
    Help {
        cmd: "sdk current".to_string(),
        tagline: "sdk subcommand to display the current default installed versions".to_string(),
        synopsis: "sdk current [candidate]".to_string(),
        description: "This subcommand will display a list of candidates with their default version installed on the \
        system. It is also possible to qualify the candidate when running the subcommand to display only that \
        candidate's default version.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "c".to_string(), command: "current".to_string() }),
        examples: "sdk current\nsdk current java".to_string(),
        ..Default::default()
    }
}

fn default_help() -> Help {
    Help {
        cmd: "sdk default".to_string(),
        tagline: "sdk subcommand to set the local default version of the candidate".to_string(),
        synopsis: "sdk default <candidate> [version]".to_string(),
        description: "The mandatory candidate qualifier of the subcommand specifies the candidate to default for all \
        future shells.\n\nThe optional version qualifier sets that specific version as default for all subsequent \
        shells on the local environment. Omitting the version will set the global SDKMAN tracked version as the \
        default version for that candidate.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "d".to_string(), command: "default".to_string() }),
        exit_code: Some("The subcommand will return a non-zero return code if the candidate or version does not exist."
            .to_string()),
        examples: "sdk default java 17.0.0-tem\nsdk default java".to_string(),
        ..Default::default()
    }
}

fn env_help() -> Help {
    let config_file_content = "\
---
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=11.0.13-tem
---"
    .italic();
    Help {
        cmd: "sdk env".to_string(),
        tagline: "sdk subcommand to control SDKs on a project level, setting up specific versions for a directory"
            .to_string(),
        synopsis: "sdk env [init|install|clear]".to_string(),
        description: format!("Allows the developer to manage the SDK versions used in a project directory. The \
        subcommand uses an {} file to install or switch specific SDK versions in a project directory.\n\nWhen \
        issuing the subcommand without a qualifier, it will switch to the versions specified in {} and emit \
        warnings for versions not present on the system. In addition, the subcommand has three optional qualifiers.",
                             ".sdkmanrc".underline(),
                             ".sdkmanrc".underline()),
        subcommands: Some(
            vec![
                Subcommand {
                    command: "install".to_string(),
                    description: format!("install and switch to the SDK versions specified in {}", ".sdkmanrc".underline()),
                },
                Subcommand {
                    command: "init".to_string(),
                    description: format!("allows for the creation of a default {} file with a single entry for the {} \
                    candidate, set to the current default value)", ".sdkmanrc".underline(), "java".italic()),
                },
                Subcommand {
                    command: "clear".to_string(),
                    description: "reset all SDK versions to their system defaults".to_string(),
                },
            ]),
        configuration: Some(
            Configuration
            {
                content: format!("The {} file contains key-value pairs for each configurable SDK for that project \
                environment. You may enable a configuration option for auto-env behaviour by setting {} in the {} \
                file. This setting will automatically switch versions when stepping into a directory on the presence \
                of a {} descriptor. When enabled, you no longer need to issue the {} qualifier explicitly. This \
                behaviour is disabled by default. An initial file will have content such as this:",
                                 ".sdkmanrc".underline(),
                                 "sdkman_auto_env=true".italic(),
                                 "$SDKMAN_DIR/etc/config".underline(),
                                 ".sdkmanrc".underline(),
                                 "install".italic()),
                snippet: config_file_content.italic().to_string(),
            }
        ),
        examples: "sdk env\nsdk env install\nsdk env init\nsdk env clear".to_string(),
        ..Default::default()
    }
}

fn flush_help() -> Help {
    Help {
        cmd: "sdk flush".to_string(),
        tagline: "sdk subcommand used for flushing local temporal state of SDKMAN".to_string(),
        synopsis: "sdk flush [tmp|metadata|version]".to_string(),
        description: format!("This command cleans temporary storage under {} in the {} and {} directories, removing \
        metadata and version caches. It also removes any residual download artifacts. It is possible to \
        flush specific targets by providing a qualifier. Omission of the qualifier results in a full flush of all \
        targets.", "$SDKMAN_DIR".underline(), "var".underline(), "tmp".underline())
            .to_string(),
        subcommands: Some(vec![
            Subcommand {
                command: "tmp".to_string(),
                description: format!("cleans out pre/post hooks and residual archives from {}", "$SDKMAN_DIR/tmp".underline()),
            },
            Subcommand {
                command: "metadata".to_string(),
                description: format!("removes any header metadata"),
            },
            Subcommand {
                command: "version".to_string(),
                description: format!(
                    "flushes the {} and {} files under {}",
                    "version".underline(),
                    "version_native".underline(),
                    "$SDKMAN_DIR/var".underline()
                ),
            },
        ]),
        examples: "sdk flush\nsdk flush tmp\nsdk flush metadata\nsdk flush version".to_string(),
        ..Default::default()
    }
}

fn home_help() -> Help {
    Help {
        cmd: "sdk home".to_string(),
        tagline: "sdk subcommand to output the path of a specific candidate version".to_string(),
        synopsis: "sdk home <candidate> <version>".to_string(),
        description: "Print the absolute home path of any candidate version installed by SDKMAN. The candidate and \
        version parameters are mandatory. This subcommand is usually used for scripting, so does not append a newline \
        character.".to_string(),
        exit_code: Some("The subcommand will emit a non-zero exit code if a valid candidate version is not locally \
        installed.".to_string()),
        examples: "sdk home java 17.0.0-tem".to_string(),
        ..Default::default()
    }
}

fn install_help() -> Help {
    Help {
        cmd: "sdk install".to_string(),
        tagline: "sdk subcommand to install a candidate version".to_string(),
        synopsis: "sdk install <candidate> [version] [path]".to_string(),
        description: "Invoking this subcommand with only the candidate as parameter will install the currently \
        known default version for that candidate. Provide a second qualifier to install a specific non-default \
        version. Provide a third optional qualifier to add an already installed local version. This final qualifier is \
        the absolute local path to the base directory of the SDK to be added. The local version will appear as an \
        installed version of the candidate. The version may not conflict with an existing version, installed or not.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "i".to_string(), command: "install".to_string() }),
        exit_code: Some("The subcommand will return a non-zero exit code for versions not found or for an invalid path.".to_string()),
        examples: "sdk install java\nsdk install java 17.0.0-tem\nsdk install java 11-local /usr/lib/jvm/java-11-openjdk".to_string(),
        ..Default::default()
    }
}

fn list_help() -> Help {
    let legend = "\
+ - local version
* - installed
> - currently in use";
    Help {
        cmd: "sdk list".to_string(),
        tagline: "sdk subcommand to list all candidates or candidate versions".to_string(),
        synopsis: "sdk list [candidate]".to_string(),
        description: format!("Invoke the subcommand without a candidate to see a comprehensive list of all candidates \
        with name, URL, detailed description and an installation command.\nIf the candidate qualifier is specified, \
        the subcommand will display a list of all available and local versions for that candidate. In addition, the \
        version list view marks all versions that are local, installed or currently in use. They appear as follows:\n
{}

Java has a custom list view with vendor-specific details.", legend.italic()),
        mnemonic: Some(Mnemonic { shorthand: "ls".to_string(), command: "list".to_string() }),
        examples: "sdk list\nsdk list java\nsdk list groovy".to_string(),
        ..Default::default()
    }
}

fn selfupdate_help() -> Help {
    Help {
        cmd: "sdk selfupdate".to_string(),
        tagline: "sdk subcommand to upgrade the SDKMAN core".to_string(),
        synopsis: "sdk selfupdate [force]".to_string(),
        description: "Invoke this command to upgrade the core script and native components of the SDKMAN command-line \
        interface. The command will only upgrade the native components if the detected platform is supported. The \
        command will refuse to upgrade the core if no new version is available. A qualifier may be added to the \
        selfupdate command to force an upgrade.".to_string(),
        examples: "sdk selfupdate\nsdk selfupdate force".to_string(),
        ..Default::default()
    }
}

fn uninstall_help() -> Help {
    Help {
        cmd: "sdk uninstall".to_string(),
        tagline: "sdk subcommand to uninstall a candidate version".to_string(),
        synopsis: "sdk uninstall <candidate> <version>".to_string(),
        description: format!("Always follow the subcommand with two qualifiers, the candidate and version to be \
        uninstalled.\n\nThe specified version will be removed from the corresponding candidate directory under {} and \
        will no longer be available for use on the system.", "$SDKMAN_DIR/candidates".underline()),
        mnemonic: Some(Mnemonic { shorthand: "rm".to_string(), command: "uninstall".to_string() }),
        exit_code: Some("An invalid candidate or version supplied to the subcommand will result in a non-zero \
        return code.".to_string()),
        examples: "sdk uninstall java 17.0.0-tem".to_string(),
        ..Default::default()
    }
}

fn update_help() -> Help {
    Help {
        cmd: "sdk update".to_string(),
        tagline: "sdk subcommand to update the local state of SDKMAN".to_string(),
        synopsis: "sdk update".to_string(),
        description: "This command is used to download information about all candidates and versions. Other \
        commands operate on this data to perform version installations and upgrades or search and display details \
        about all packages available for installation. Run this command often to ensure that all candidates are \
        up to date and that the latest versions will be visible and installed.".to_string(),
        examples: "sdk update".to_string(),
        ..Default::default()
    }
}

fn upgrade_help() -> Help {
    Help {
        cmd: "sdk upgrade".to_string(),
        tagline: "sdk subcommand to upgrade installed candidate versions".to_string(),
        synopsis: "sdk upgrade [candidate]".to_string(),
        description: "The optional candidate qualifier can be applied to specify the candidate you want to upgrade. \
        If the candidate qualifier is omitted from the command, it will attempt an upgrade of all outdated \
        candidates.\nCandidates that do not require an upgrade will be omitted, and a notification will be displayed \
        that these candidates are up to date.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "ug".to_string(), command: "upgrade".to_string() }),
        exit_code: Some("The subcommand will return a non-zero return code if the candidate does not exist.".to_string()),
        examples: "sdk upgrade\nsdk upgrade java".to_string(),
        ..Default::default()
    }
}

fn use_help() -> Help {
    Help {
        cmd: "sdk use".to_string(),
        tagline: "sdk subcommand to use a specific version only in the current shell".to_string(),
        synopsis: "sdk use <candidate> <version>".to_string(),
        description: "The mandatory candidate and version follow the subcommand to specify what to use in the \
        shell. This subcommand only operates on the current shell. It does not affect other shells \
        running different versions of the same candidate. It also does not change the default version set for \
        all subsequent shells.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "u".to_string(), command: "use".to_string() }),
        exit_code: Some("The subcommand will return a non-zero return code if the candidate or version does not exist."
            .to_string()),
        examples: "sdk use java 17.0.0-tem".to_string(),
        ..Default::default()
    }
}

fn version_help() -> Help {
    Help {
        cmd: "sdk version".to_string(),
        tagline: "sdk subcommand to display the installed SDKMAN version".to_string(),
        synopsis: "sdk version".to_string(),
        description: "This subcommand displays the version of the bash and native components of SDKMAN on this \
        system. The versions of the bash and native libraries evolve independently from each other and so will not \
        be in sync.".to_string(),
        mnemonic: Some(Mnemonic { shorthand: "v".to_string(), command: "version".to_string() }),
        examples: "sdk version".to_string(),
        ..Default::default()
    }
}

#[cfg(test)]
mod tests {
    use crate::{
        config_help, current_help, default_help, env_help, flush_help, home_help, install_help,
        list_help, main_help, render, selfupdate_help, uninstall_help, update_help, upgrade_help,
        use_help, version_help,
    };

    #[test]
    fn render_main_help() {
        let help_text = "
NAME
    sdk - The command line interface (CLI) for SDKMAN!

SYNOPSIS
    sdk <subcommand> [candidate] [version]

DESCRIPTION
    SDKMAN! is a tool for managing parallel versions of multiple JVM related
    Software Development Kits on most Unix based systems. It provides a
    convenient Command Line Interface (CLI) and API for installing, switching,
    removing and listing Candidates.

SUBCOMMANDS & QUALIFIERS
    help         [subcommand]
    install      <candidate> [version] [path]
    uninstall    <candidate> <version>
    list         [candidate]
    use          <candidate> <version>
    config       no qualifier
    default      <candidate> [version]
    home         <candidate> <version>
    env          [init|install|clear]
    current      [candidate]
    upgrade      [candidate]
    version      no qualifier
    offline      [enable|disable]
    selfupdate   [force]
    update       no qualifier
    flush        [tmp|metadata|version]

EXAMPLES
    sdk install java 17.0.0-tem
    sdk help install

";
        colored::control::set_override(false);
        assert_eq!(help_text, render(main_help()));
    }

    #[test]
    fn render_config_help() {
        let config_text = "
NAME
    sdk config - sdk subcommand to edit the SDKMAN configuration file

SYNOPSIS
    sdk config

DESCRIPTION
    This subcommand opens a text editor on the configuration file located at
    ${SDKMAN_DIR}/etc/config. The subcommand will infer the text editor from
    the EDITOR environment variable. If the system does not set the EDITOR
    environment variable, then vi is assumed as the default editor.

CONFIGURATION
    The ${SDKMAN_DIR}/etc/config file contains the following default
    configuration. A new shell should be opened for any configuration changes to
    take effect.

    ---
    sdkman_auto_answer=false
    sdkman_auto_complete=true
    sdkman_auto_env=false
    sdkman_auto_update=true
    sdkman_beta_channel=false
    sdkman_checksum_enable=true
    sdkman_colour_enable=true
    sdkman_curl_connect_timeout=7
    sdkman_curl_max_time=10
    sdkman_debug_mode=false
    sdkman_insecure_ssl=false
    sdkman_selfupdate_feature=true
    ---

EXAMPLES
    sdk config

";
        colored::control::set_override(false);
        assert_eq!(config_text, render(config_help()));
    }

    #[test]
    fn render_current_help() {
        let current_text = "
NAME
    sdk current - sdk subcommand to display the current default installed
    versions

SYNOPSIS
    sdk current [candidate]

DESCRIPTION
    This subcommand will display a list of candidates with their default version
    installed on the system. It is also possible to qualify the candidate when
    running the subcommand to display only that candidate's default version.

MNEMONIC
    c - may be used in place of the current subcommand.

EXAMPLES
    sdk current
    sdk current java

";
        colored::control::set_override(false);
        assert_eq!(current_text, render(current_help()));
    }

    #[test]
    fn render_default_help() {
        let default_text = "
NAME
    sdk default - sdk subcommand to set the local default version of the
    candidate

SYNOPSIS
    sdk default <candidate> [version]

DESCRIPTION
    The mandatory candidate qualifier of the subcommand specifies the candidate
    to default for all future shells.

    The optional version qualifier sets that specific version as default for all
    subsequent shells on the local environment. Omitting the version will set
    the global SDKMAN tracked version as the default version for that candidate.

EXIT CODE
    The subcommand will return a non-zero return code if the candidate or
    version does not exist.

MNEMONIC
    d - may be used in place of the default subcommand.

EXAMPLES
    sdk default java 17.0.0-tem
    sdk default java

";
        colored::control::set_override(false);
        assert_eq!(default_text, render(default_help()));
    }

    #[test]
    fn render_env_help() {
        let env_text = "
NAME
    sdk env - sdk subcommand to control SDKs on a project level, setting up
    specific versions for a directory

SYNOPSIS
    sdk env [init|install|clear]

DESCRIPTION
    Allows the developer to manage the SDK versions used in a project directory.
    The subcommand uses an .sdkmanrc file to install or switch specific SDK
    versions in a project directory.

    When issuing the subcommand without a qualifier, it will switch to the
    versions specified in .sdkmanrc and emit warnings for versions not present
    on the system. In addition, the subcommand has three optional qualifiers.

SUBCOMMANDS & QUALIFIERS
    install      install and switch to the SDK versions specified
                 in .sdkmanrc
    init         allows for the creation of a default .sdkmanrc file with
                 a single entry for the java candidate, set to the current
                 default value)
    clear        reset all SDK versions to their system defaults

CONFIGURATION
    The .sdkmanrc file contains key-value pairs for each configurable SDK for
    that project environment. You may enable a configuration option for auto-
    env behaviour by setting sdkman_auto_env=true in the $SDKMAN_DIR/etc/config
    file. This setting will automatically switch versions when stepping into a
    directory on the presence of a .sdkmanrc descriptor. When enabled, you no
    longer need to issue the install qualifier explicitly. This behaviour is
    disabled by default. An initial file will have content such as this:

    ---
    # Enable auto-env through the sdkman_auto_env config
    # Add key=value pairs of SDKs to use below
    java=11.0.13-tem
    ---

EXAMPLES
    sdk env
    sdk env install
    sdk env init
    sdk env clear

";
        colored::control::set_override(false);
        assert_eq!(env_text, render(env_help()));
    }

    #[test]
    fn render_flush_help() {
        let flush_text = "
NAME
    sdk flush - sdk subcommand used for flushing local temporal state of SDKMAN

SYNOPSIS
    sdk flush [tmp|metadata|version]

DESCRIPTION
    This command cleans temporary storage under $SDKMAN_DIR in the var and
    tmp directories, removing metadata and version caches. It also removes any
    residual download artifacts. It is possible to flush specific targets by
    providing a qualifier. Omission of the qualifier results in a full flush of
    all targets.

SUBCOMMANDS & QUALIFIERS
    tmp          cleans out pre/post hooks and residual archives from
                 $SDKMAN_DIR/tmp
    metadata     removes any header metadata
    version      flushes the version and version_native files under
                 $SDKMAN_DIR/var

EXAMPLES
    sdk flush
    sdk flush tmp
    sdk flush metadata
    sdk flush version

";
        colored::control::set_override(false);
        assert_eq!(flush_text, render(flush_help()));
    }

    #[test]
    fn render_home_help() {
        let home_text = "
NAME
    sdk home - sdk subcommand to output the path of a specific candidate version

SYNOPSIS
    sdk home <candidate> <version>

DESCRIPTION
    Print the absolute home path of any candidate version installed by SDKMAN.
    The candidate and version parameters are mandatory. This subcommand is
    usually used for scripting, so does not append a newline character.

EXIT CODE
    The subcommand will emit a non-zero exit code if a valid candidate version
    is not locally installed.

EXAMPLES
    sdk home java 17.0.0-tem

";
        colored::control::set_override(false);
        assert_eq!(home_text, render(home_help()));
    }

    #[test]
    fn render_install_help() {
        let install_text = "
NAME
    sdk install - sdk subcommand to install a candidate version

SYNOPSIS
    sdk install <candidate> [version] [path]

DESCRIPTION
    Invoking this subcommand with only the candidate as parameter will install
    the currently known default version for that candidate. Provide a second
    qualifier to install a specific non-default version. Provide a third
    optional qualifier to add an already installed local version. This final
    qualifier is the absolute local path to the base directory of the SDK to
    be added. The local version will appear as an installed version of the
    candidate. The version may not conflict with an existing version, installed
    or not.

EXIT CODE
    The subcommand will return a non-zero exit code for versions not found or
    for an invalid path.

MNEMONIC
    i - may be used in place of the install subcommand.

EXAMPLES
    sdk install java
    sdk install java 17.0.0-tem
    sdk install java 11-local /usr/lib/jvm/java-11-openjdk

";
        colored::control::set_override(false);
        assert_eq!(install_text, render(install_help()));
    }

    #[test]
    fn render_list_help() {
        let list_text = "
NAME
    sdk list - sdk subcommand to list all candidates or candidate versions

SYNOPSIS
    sdk list [candidate]

DESCRIPTION
    Invoke the subcommand without a candidate to see a comprehensive list of all
    candidates with name, URL, detailed description and an installation command.
    If the candidate qualifier is specified, the subcommand will display a list
    of all available and local versions for that candidate. In addition, the
    version list view marks all versions that are local, installed or currently
    in use. They appear as follows:

    + - local version
    * - installed
    > - currently in use

    Java has a custom list view with vendor-specific details.

MNEMONIC
    ls - may be used in place of the list subcommand.

EXAMPLES
    sdk list
    sdk list java
    sdk list groovy

";
        colored::control::set_override(false);
        assert_eq!(list_text, render(list_help()));
    }

    #[test]
    fn render_selfupdate_help() {
        let selfupdate_text = "
NAME
    sdk selfupdate - sdk subcommand to upgrade the SDKMAN core

SYNOPSIS
    sdk selfupdate [force]

DESCRIPTION
    Invoke this command to upgrade the core script and native components of
    the SDKMAN command-line interface. The command will only upgrade the native
    components if the detected platform is supported. The command will refuse to
    upgrade the core if no new version is available. A qualifier may be added to
    the selfupdate command to force an upgrade.

EXAMPLES
    sdk selfupdate
    sdk selfupdate force

";
        colored::control::set_override(false);
        assert_eq!(selfupdate_text, render(selfupdate_help()));
    }

    #[test]
    fn render_uninstall_help() {
        let uninstall_text = "
NAME
    sdk uninstall - sdk subcommand to uninstall a candidate version

SYNOPSIS
    sdk uninstall <candidate> <version>

DESCRIPTION
    Always follow the subcommand with two qualifiers, the candidate and version
    to be uninstalled.

    The specified version will be removed from the corresponding candidate
    directory under $SDKMAN_DIR/candidates and will no longer be available for
    use on the system.

EXIT CODE
    An invalid candidate or version supplied to the subcommand will result in a
    non-zero return code.

MNEMONIC
    rm - may be used in place of the uninstall subcommand.

EXAMPLES
    sdk uninstall java 17.0.0-tem

";
        colored::control::set_override(false);
        assert_eq!(uninstall_text, render(uninstall_help()));
    }

    #[test]
    fn render_update_help() {
        let update_text = "
NAME
    sdk update - sdk subcommand to update the local state of SDKMAN

SYNOPSIS
    sdk update

DESCRIPTION
    This command is used to download information about all candidates
    and versions. Other commands operate on this data to perform version
    installations and upgrades or search and display details about all packages
    available for installation. Run this command often to ensure that all
    candidates are up to date and that the latest versions will be visible and
    installed.

EXAMPLES
    sdk update

";
        colored::control::set_override(false);
        assert_eq!(update_text, render(update_help()));
    }

    #[test]
    fn render_upgrade_help() {
        let upgrade_text = "
NAME
    sdk upgrade - sdk subcommand to upgrade installed candidate versions

SYNOPSIS
    sdk upgrade [candidate]

DESCRIPTION
    The optional candidate qualifier can be applied to specify the candidate you
    want to upgrade. If the candidate qualifier is omitted from the command, it
    will attempt an upgrade of all outdated candidates.
    Candidates that do not require an upgrade will be omitted, and a
    notification will be displayed that these candidates are up to date.

EXIT CODE
    The subcommand will return a non-zero return code if the candidate does
    not exist.

MNEMONIC
    ug - may be used in place of the upgrade subcommand.

EXAMPLES
    sdk upgrade
    sdk upgrade java

";
        colored::control::set_override(false);
        assert_eq!(upgrade_text, render(upgrade_help()));
    }

    #[test]
    fn render_use_help() {
        let use_text = "
NAME
    sdk use - sdk subcommand to use a specific version only in the current shell

SYNOPSIS
    sdk use <candidate> <version>

DESCRIPTION
    The mandatory candidate and version follow the subcommand to specify
    what to use in the shell. This subcommand only operates on the current
    shell. It does not affect other shells running different versions of the
    same candidate. It also does not change the default version set for all
    subsequent shells.

EXIT CODE
    The subcommand will return a non-zero return code if the candidate or
    version does not exist.

MNEMONIC
    u - may be used in place of the use subcommand.

EXAMPLES
    sdk use java 17.0.0-tem

";
        colored::control::set_override(false);
        assert_eq!(use_text, render(use_help()));
    }

    #[test]
    fn render_version_help() {
        let version_text = "
NAME
    sdk version - sdk subcommand to display the installed SDKMAN version

SYNOPSIS
    sdk version

DESCRIPTION
    This subcommand displays the version of the bash and native components of
    SDKMAN on this system. The versions of the bash and native libraries evolve
    independently from each other and so will not be in sync.

MNEMONIC
    v - may be used in place of the version subcommand.

EXAMPLES
    sdk version

";
        colored::control::set_override(false);
        assert_eq!(version_text, render(version_help()));
    }
}