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