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
// Copyright (c) ZeroC, Inc.
use crate::diagnostics::Lint;
use clap::ArgAction::Append;
use clap::{Parser, ValueEnum};
// Note: clap uses the doc-comments of fields to populate the '--help' output of slicec-xxx.
// boolean flags automatically default to false, and strings automatically default to empty.
/// This struct is responsible for parsing the command line options common to all slice compilers.
/// The option parsing capabilities are generated on the struct by the `clap` macro.
#[derive(Debug, Default, Parser)]
#[command(rename_all = "kebab-case")]
pub struct SliceOptions {
/// List of Slice files to compile.
#[arg(required = true)]
pub sources: Vec<String>,
/// Add a directory or Slice file to the list of references.
#[arg(short = 'R', num_args = 1, action = Append, value_name = "REFERENCE")]
pub references: Vec<String>,
/// Define a preprocessor symbol.
#[arg(short = 'D', num_args = 1, action = Append, value_name = "SYMBOL")]
pub defined_symbols: Vec<String>,
/// Instruct the compiler to allow the specified lint.
// TODO add a link to the lint reference in this doc comment!
#[arg(short = 'A', long = "allow", num_args = 1, action = Append, value_name = "LINT_NAME", value_parser = Lint::ALLOWABLE_LINT_IDENTIFIERS, hide_possible_values = true, ignore_case = true)]
pub allowed_lints: Vec<String>,
/// Validate input files without generating code for them.
#[arg(long)]
pub dry_run: bool,
/// Set the output directory for the generated code. Defaults to the current working directory.
#[arg(short = 'O', long, value_name = "DIRECTORY")]
pub output_dir: Option<String>,
/// Set which format to emit errors and warnings with.
#[arg(long, value_name = "FORMAT", value_enum, default_value_t = DiagnosticFormat::Human, ignore_case = true)]
pub diagnostic_format: DiagnosticFormat,
/// Disable ANSI color codes in diagnostic output.
#[arg(long)]
pub disable_color: bool,
}
/// This enum is used to specify the format for emitted diagnostics.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
pub enum DiagnosticFormat {
/// Diagnostics are printed to the console in an easily readable format with source code snippets when possible.
#[default]
Human,
/// Diagnostics will be serialized as JSON objects and printed to the console, one diagnostic per line.
Json,
}