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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#![allow(clippy::doc_overindented_list_items)]
use aiken_lang::ast::{TraceLevel, Tracing};
use aiken_project::{
options::BlueprintExport,
watch::{self, watch_project, with_project},
};
use clap::builder::{MapValueParser, PossibleValuesParser, TypedValueParser};
use std::{path::PathBuf, process};
#[derive(clap::Args)]
#[clap(disable_version_flag(true))]
/// Build an Aiken project
pub struct Args {
/// Path to project
directory: Option<PathBuf>,
/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,
/// Silence warnings; warnings will not be printed
#[clap(short = 'S', long)]
silent: bool,
/// When enabled, re-run the command on file changes instead of exiting
#[clap(short, long)]
watch: bool,
/// Also dump textual uplc
#[clap(short, long)]
uplc: bool,
/// Environment to build against.
#[clap(long)]
env: Option<String>,
/// Optional relative filepath to the generated Plutus blueprint.
///
/// [default: plutus.json]
#[clap(
short,
long("out"),
value_parser,
value_name = "FILEPATH",
verbatim_doc_comment
)]
output: Option<PathBuf>,
/// Filter traces to be included in the generated program(s).
///
/// - user-defined:
/// only consider traces that you've explicitly defined
/// either through the 'trace' keyword of via the trace-if-false
/// ('?') operator.
///
/// - compiler-generated:
/// only included internal traces generated by the
/// Aiken compiler, for example in usage of 'expect'.
///
/// - all:
/// include both user-defined and compiler-generated traces.
///
/// [optional] [default: all]
#[clap(short = 'f', long, value_parser=trace_filter_parser(), default_missing_value="all", verbatim_doc_comment, alias="filter_traces")]
trace_filter: Option<fn(TraceLevel) -> Tracing>,
/// Choose the verbosity level of traces:
///
/// - silent:
/// disable traces altogether
///
/// - compact:
/// only culprit line numbers are shown on failures
///
/// - verbose:
/// enable full verbose traces as provided by the user or the compiler
///
/// [optional]
#[clap(short, long, value_parser=trace_level_parser(), default_value_t=TraceLevel::Silent, verbatim_doc_comment)]
trace_level: TraceLevel,
/// Include all serialisable types in the blueprint, not only those present in validators
/// signatures. Off by default.
#[clap(short = 'I', long)]
include_all_types: bool,
}
pub fn exec(
Args {
directory,
deny,
silent,
watch,
uplc,
trace_filter,
trace_level,
output,
env,
include_all_types,
}: Args,
) -> miette::Result<()> {
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.build(
uplc,
match trace_filter {
Some(trace_filter) => trace_filter(trace_level),
None => Tracing::All(trace_level),
},
p.blueprint_path(output.as_deref()),
BlueprintExport::from(include_all_types),
env.clone(),
)
})
} else {
with_project(directory.as_deref(), deny, silent, true, |p| {
p.build(
uplc,
match trace_filter {
Some(trace_filter) => trace_filter(trace_level),
None => Tracing::All(trace_level),
},
p.blueprint_path(output.as_deref()),
BlueprintExport::from(include_all_types),
env.clone(),
)
})
};
result.map_err(|_| process::exit(1))
}
#[allow(clippy::type_complexity)]
pub fn trace_filter_parser()
-> MapValueParser<PossibleValuesParser, fn(String) -> fn(TraceLevel) -> Tracing> {
PossibleValuesParser::new(["user-defined", "compiler-generated", "all"]).map(
|s: String| match s.as_str() {
"user-defined" => Tracing::UserDefined,
"compiler-generated" => Tracing::CompilerGenerated,
"all" => Tracing::All,
_ => unreachable!(),
},
)
}
#[allow(clippy::type_complexity)]
pub fn trace_level_parser() -> MapValueParser<PossibleValuesParser, fn(String) -> TraceLevel> {
PossibleValuesParser::new(["silent", "compact", "verbose"]).map(|s| match s.as_str() {
"silent" => TraceLevel::Silent,
"compact" => TraceLevel::Compact,
"verbose" => TraceLevel::Verbose,
_ => unreachable!(),
})
}