iceoryx2_cli/
cli.rs

1// Copyright (c) 2024 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13use colored::*;
14
15pub enum HelpOptions {
16    DontPrintCommandSection,
17    PrintCommandSection,
18    PrintCommandSectionWithExternalCommandHint,
19}
20
21pub fn help_template(command_help: HelpOptions) -> String {
22    let mut template = format!(
23        "{{about}}\n\n\
24         {} {{usage}}\n\n\
25         {{positionals}}\n\n\
26         {}\n\
27         {{options}}",
28        "Usage:".bright_green().bold(),
29        "Options:".bright_green().bold(),
30    );
31
32    match command_help {
33        HelpOptions::PrintCommandSection
34        | HelpOptions::PrintCommandSectionWithExternalCommandHint => {
35            template.push_str(&format!(
36                "\n\n\
37                {}\n\
38                {{subcommands}}",
39                "Commands:".bright_green().bold(),
40            ));
41
42            if let HelpOptions::PrintCommandSectionWithExternalCommandHint = command_help {
43                template.push_str(&format!(
44                    "\n\
45                    {}{}",
46                    "  ...            ".bold(),
47                    "See external installed commands with --list"
48                ));
49            }
50        }
51        HelpOptions::DontPrintCommandSection => {}
52    }
53
54    template
55}