| 1 |
// Copyright 2023 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::io::Write as _; |
| 16 |
|
| 17 |
use jj_cli::cli_util::CliRunner; |
| 18 |
use jj_cli::command_error::CommandError; |
| 19 |
use jj_cli::ui::Ui; |
| 20 |
|
| 21 |
#[derive(clap::Args, Clone, Debug)] |
| 22 |
struct CustomGlobalArgs { |
| 23 |
/// Show a greeting before each command |
| 24 |
#[arg(long, global = true)] |
| 25 |
greet: bool, |
| 26 |
} |
| 27 |
|
| 28 |
fn process_before(ui: &mut Ui, custom_global_args: CustomGlobalArgs) -> Result<(), CommandError> { |
| 29 |
if custom_global_args.greet { |
| 30 |
writeln!(ui.stdout(), "Hello!")?; |
| 31 |
} |
| 32 |
Ok(()) |
| 33 |
} |
| 34 |
|
| 35 |
fn main() -> std::process::ExitCode { |
| 36 |
CliRunner::init() |
| 37 |
.add_global_args(process_before) |
| 38 |
.run() |
| 39 |
.into() |
| 40 |
} |