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         {}\n\
26         {{options}}",
27        "Usage:".bright_green().bold(),
28        "Options:".bright_green().bold(),
29    );
30
31    match command_help {
32        HelpOptions::PrintCommandSection
33        | HelpOptions::PrintCommandSectionWithExternalCommandHint => {
34            template.push_str(&format!(
35                "\n\n\
36                {}\n\
37                {{subcommands}}",
38                "Commands:".bright_green().bold(),
39            ));
40
41            if let HelpOptions::PrintCommandSectionWithExternalCommandHint = command_help {
42                template.push_str(&format!(
43                    "\n\
44                    {}{}",
45                    "  ...            ".bold(),
46                    "See external installed commands with --list"
47                ));
48            }
49        }
50        HelpOptions::DontPrintCommandSection => {}
51    }
52
53    template
54}