Skip to main content

just/
lib.rs

1//! `just` is a handy way to save and run project-specific commands, and is
2//! primarily used as a command-line binary.
3//!
4//! See [GitHub](https://github.com/casey/just/) for more information.
5//!
6//! A limited public library interface is available. Please keep in mind that
7//! there are no semantic version guarantees for the library interface. It may
8//! break or change at any time.
9
10pub(crate) use {
11  crate::{
12    alias::Alias,
13    alias_style::AliasStyle,
14    analyzer::Analyzer,
15    arg_attribute::ArgAttribute,
16    assignment::Assignment,
17    ast::Ast,
18    attribute::{Attribute, AttributeKind},
19    attribute_set::AttributeSet,
20    binding::Binding,
21    cache::Cache,
22    cache_entry::CacheEntry,
23    cache_key::CacheKey,
24    cache_lock::CacheLock,
25    cache_status::CacheStatus,
26    clean::Clean,
27    color::Color,
28    color_display::ColorDisplay,
29    command_color::CommandColor,
30    command_ext::CommandExt,
31    compilation::Compilation,
32    compile_error::CompileError,
33    compile_error_kind::CompileErrorKind,
34    compiler::Compiler,
35    completer::Completer,
36    conditional_operator::ConditionalOperator,
37    config::Config,
38    config_error::ConfigError,
39    const_error::ConstError,
40    const_eval_error::ConstEvalError,
41    constants::constants,
42    count::Count,
43    datetime_format::datetime_format,
44    datetime_format_error::DatetimeFormatError,
45    delimiter::Delimiter,
46    dependency::Dependency,
47    dependency_argument::DependencyArgument,
48    disabled::Disabled,
49    dump_format::DumpFormat,
50    element::Element,
51    enclosure::Enclosure,
52    environment::Environment,
53    error::Error,
54    evaluate_format::EvaluateFormat,
55    evaluator::Evaluator,
56    execution_context::ExecutionContext,
57    executor::Executor,
58    expression::Expression,
59    expression_context::ExpressionContext,
60    format_string_part::FormatStringPart,
61    fragment::Fragment,
62    function::Function,
63    function_definition::FunctionDefinition,
64    indentation::Indentation,
65    interpreter::Interpreter,
66    invocation::Invocation,
67    invocation_parser::InvocationParser,
68    item::{Item, ItemKind},
69    justfile::Justfile,
70    keyed::Keyed,
71    keyword::Keyword,
72    layer::Layer,
73    lexer::Lexer,
74    line::Line,
75    list::List,
76    list_entry::ListEntry,
77    list_feature::ListFeature,
78    list_operator::ListOperator,
79    load_dotenv::load_dotenv,
80    loader::Loader,
81    modulepath::Modulepath,
82    name::Name,
83    namepath::Namepath,
84    number::Number,
85    numerator::Numerator,
86    ordinal::Ordinal,
87    output_error::OutputError,
88    parameter::Parameter,
89    parameter_kind::ParameterKind,
90    parser::Parser,
91    pattern::Pattern,
92    platform::Platform,
93    platform_interface::PlatformInterface,
94    position::Position,
95    positional::Positional,
96    ran::Ran,
97    range_ext::RangeExt,
98    recipe::Recipe,
99    recipe_resolver::RecipeResolver,
100    recipe_signature::RecipeSignature,
101    reference::Reference,
102    references::References,
103    request::Request,
104    resolution::Resolution,
105    scope::Scope,
106    search::Search,
107    search_config::SearchConfig,
108    search_error::SearchError,
109    semaphore::Semaphore,
110    set::Set,
111    setting::Setting,
112    settings::Settings,
113    shebang::Shebang,
114    shell::Shell,
115    shell_kind::ShellKind,
116    show_whitespace::ShowWhitespace,
117    sigil::Sigil,
118    signal::Signal,
119    signal_handler::SignalHandler,
120    source::Source,
121    string_context::StringContext,
122    string_delimiter::StringDelimiter,
123    string_kind::StringKind,
124    string_literal::StringLiteral,
125    string_state::StringState,
126    style::Style,
127    subcommand::Subcommand,
128    suggestion::Suggestion,
129    switch::Switch,
130    table::Table,
131    tangle::tangle,
132    token::Token,
133    token_kind::TokenKind,
134    unresolved_dependency::UnresolvedDependency,
135    unresolved_recipe::UnresolvedRecipe,
136    unstable_feature::UnstableFeature,
137    usage::Usage,
138    use_color::UseColor,
139    value::Value,
140    variable_resolver::VariableResolver,
141    verbosity::Verbosity,
142    version::Version,
143    warning::Warning,
144    which::which,
145  },
146  camino::Utf8Path,
147  chrono::{DateTime, Local, TimeZone, Utc, format::StrftimeItems},
148  clap::{CommandFactory, FromArgMatches, Parser as _, ValueEnum},
149  clap_complete::{ArgValueCompleter, CompletionCandidate, PathCompleter, engine::ValueCompleter},
150  digest_io::HashWriter,
151  libc::EXIT_FAILURE,
152  rand::seq::IndexedRandom,
153  regex::Regex,
154  serde::{
155    Deserialize, Deserializer, Serialize, Serializer,
156    ser::{SerializeMap, SerializeSeq, SerializeStruct},
157  },
158  sha2::{Digest, Sha256},
159  snafu::{ResultExt, Snafu},
160  std::{
161    borrow::Borrow,
162    cmp::Ordering,
163    collections::{BTreeMap, BTreeSet, HashMap, HashSet, btree_map},
164    env::{self, VarError},
165    ffi::{OsStr, OsString},
166    fmt::{self, Debug, Display, Formatter},
167    fs::{self, File},
168    io::{self, Seek, Sink, Write},
169    iter::{self, FromIterator},
170    mem,
171    num::{NonZeroU64, ParseIntError},
172    ops::Deref,
173    ops::{Index, RangeInclusive},
174    path::{self, Component, Path, PathBuf},
175    process::{self, Command, ExitStatus, Stdio},
176    slice,
177    str::{self, Chars, FromStr},
178    sync::{Arc, Condvar, LazyLock, Mutex, MutexGuard},
179    thread,
180    time::Instant,
181    vec,
182  },
183  strum::{Display, EnumDiscriminants, EnumIter, EnumString, IntoStaticStr},
184  tempfile::TempDir,
185  typed_arena::Arena,
186  unicode_width::{UnicodeWidthChar, UnicodeWidthStr},
187};
188
189#[cfg(test)]
190pub(crate) use {
191  crate::{node::Node, tree::Tree},
192  std::borrow::Cow,
193};
194
195pub use crate::run::run;
196
197#[doc(hidden)]
198pub use {arguments::Arguments, request::Response, subcommand::INIT_JUSTFILE, unindent::unindent};
199
200type CompileResult<'a, T = ()> = Result<T, CompileError<'a>>;
201type ConfigResult<T> = Result<T, ConfigError>;
202type RunResult<'a, T = ()> = Result<T, Error<'a>>;
203type SearchResult<T> = Result<T, SearchError>;
204type StringResult = Result<String, String>;
205type ValueResult = Result<Value, String>;
206
207type ModuleAlias<'src> = Alias<'src, Modulepath>;
208type RecipeAlias<'src> = Alias<'src, Arc<Recipe<'src>>>;
209
210const JUST_DIRECTORY: &str = "just";
211const RECURSION_LIMIT: usize = if cfg!(windows) { 48 } else { 256 };
212const TEMPDIR_PREFIX: &str = "just-";
213const VERSION: &str = env!("CARGO_PKG_VERSION");
214
215fn signal_exit_code(number: i32) -> Option<i32> {
216  number.checked_add(128)
217}
218
219#[cfg(test)]
220#[macro_use]
221pub mod testing;
222
223#[cfg(test)]
224#[macro_use]
225pub mod tree;
226
227#[cfg(test)]
228pub mod node;
229
230// Used for testing with the `--request` subcommand.
231#[doc(hidden)]
232pub mod request;
233
234mod alias;
235mod alias_style;
236mod analyzer;
237mod arg_attribute;
238mod arguments;
239mod assignment;
240mod ast;
241mod attribute;
242mod attribute_set;
243mod binding;
244mod cache;
245mod cache_entry;
246mod cache_key;
247mod cache_lock;
248mod cache_status;
249mod clean;
250mod color;
251mod color_display;
252mod command_color;
253mod command_ext;
254mod compilation;
255mod compile_error;
256mod compile_error_kind;
257mod compiler;
258mod completer;
259mod conditional_operator;
260mod config;
261mod config_error;
262mod const_error;
263mod const_eval_error;
264mod constants;
265mod count;
266mod datetime_format;
267mod datetime_format_error;
268mod delimiter;
269mod dependency;
270mod dependency_argument;
271mod disabled;
272mod dump_format;
273mod element;
274mod enclosure;
275mod environment;
276mod error;
277mod evaluate_format;
278mod evaluator;
279mod execution_context;
280mod executor;
281mod expression;
282mod expression_context;
283mod filesystem;
284mod format_string_part;
285mod fragment;
286mod function;
287mod function_definition;
288mod indentation;
289mod interpreter;
290mod invocation;
291mod invocation_parser;
292mod item;
293mod justfile;
294mod keyed;
295mod keyword;
296mod layer;
297mod lexer;
298mod line;
299mod list;
300mod list_entry;
301mod list_feature;
302mod list_operator;
303mod load_dotenv;
304mod loader;
305mod modulepath;
306mod name;
307mod namepath;
308mod number;
309mod numerator;
310mod ordinal;
311mod output_error;
312mod parameter;
313mod parameter_kind;
314mod parser;
315mod pattern;
316mod platform;
317mod platform_interface;
318mod position;
319mod positional;
320mod ran;
321mod range_ext;
322mod recipe;
323mod recipe_resolver;
324mod recipe_signature;
325mod reference;
326mod references;
327mod resolution;
328mod run;
329mod scope;
330mod search;
331mod search_config;
332mod search_error;
333mod semaphore;
334mod set;
335mod setting;
336mod settings;
337mod shebang;
338mod shell;
339mod shell_kind;
340mod show_whitespace;
341mod sigil;
342mod signal;
343mod signal_handler;
344#[cfg(unix)]
345mod signals;
346mod source;
347mod string_context;
348mod string_delimiter;
349mod string_kind;
350mod string_literal;
351mod string_state;
352mod style;
353mod subcommand;
354mod suggestion;
355mod switch;
356mod table;
357mod tangle;
358mod token;
359mod token_kind;
360mod unindent;
361mod unresolved_dependency;
362mod unresolved_recipe;
363mod unstable_feature;
364mod usage;
365mod use_color;
366mod value;
367mod variable_resolver;
368mod verbosity;
369mod version;
370mod warning;
371mod which;