2024-01-01 14:58:21 -05:00
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2020-09-05 20:34:02 -04:00
2024-01-23 13:56:50 -05:00
use clap ::builder ::styling ::AnsiColor ;
2023-10-20 00:02:08 -04:00
use clap ::builder ::FalseyValueParser ;
2023-03-26 00:06:18 -04:00
use clap ::value_parser ;
2019-06-26 06:02:13 -04:00
use clap ::Arg ;
2023-03-26 00:06:18 -04:00
use clap ::ArgAction ;
2019-06-26 06:02:13 -04:00
use clap ::ArgMatches ;
2022-01-14 11:38:17 -05:00
use clap ::ColorChoice ;
2022-03-27 21:57:56 -04:00
use clap ::Command ;
2022-03-14 14:41:35 -04:00
use clap ::ValueHint ;
2024-08-21 09:54:59 -04:00
use color_print ::cstr ;
2024-08-30 17:58:24 -04:00
use deno_config ::deno_json ::NodeModulesDirMode ;
2024-07-03 20:54:33 -04:00
use deno_config ::glob ::FilePatterns ;
2024-03-27 18:47:46 -04:00
use deno_config ::glob ::PathOrPatternSet ;
2024-05-06 19:21:58 -04:00
use deno_core ::anyhow ::bail ;
2024-03-27 18:47:46 -04:00
use deno_core ::anyhow ::Context ;
use deno_core ::error ::AnyError ;
2024-07-03 20:54:33 -04:00
use deno_core ::normalize_path ;
2023-03-13 21:12:09 -04:00
use deno_core ::resolve_url_or_path ;
2021-01-07 13:06:08 -05:00
use deno_core ::url ::Url ;
2023-06-07 10:09:10 -04:00
use deno_graph ::GraphKind ;
2024-06-06 23:37:53 -04:00
use deno_runtime ::deno_permissions ::parse_sys_kind ;
use deno_runtime ::deno_permissions ::PermissionsOptions ;
2021-03-26 12:34:25 -04:00
use log ::debug ;
2019-06-22 12:02:51 -04:00
use log ::Level ;
2024-05-06 19:21:58 -04:00
use serde ::Deserialize ;
use serde ::Serialize ;
2024-07-08 10:12:10 -04:00
use std ::collections ::HashSet ;
2022-04-18 15:08:30 -04:00
use std ::env ;
2024-03-22 17:03:56 -04:00
use std ::ffi ::OsString ;
2020-04-03 13:40:11 -04:00
use std ::net ::SocketAddr ;
2021-09-13 16:06:45 -04:00
use std ::num ::NonZeroU32 ;
use std ::num ::NonZeroU8 ;
2021-08-23 06:35:38 -04:00
use std ::num ::NonZeroUsize ;
2023-03-13 21:12:09 -04:00
use std ::path ::Path ;
2020-05-29 11:27:43 -04:00
use std ::path ::PathBuf ;
2020-11-12 17:17:31 -05:00
use std ::str ::FromStr ;
2019-11-26 11:06:32 -05:00
2024-05-06 19:21:58 -04:00
use crate ::args ::resolve_no_prompt ;
2023-02-23 10:58:10 -05:00
use crate ::util ::fs ::canonicalize_path ;
2023-08-03 07:19:19 -04:00
use super ::flags_net ;
2022-06-27 16:54:09 -04:00
2024-07-19 15:56:07 -04:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
pub enum ConfigFlag {
#[ default ]
Discover ,
Path ( String ) ,
Disabled ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
pub struct FileFlags {
2024-01-15 19:15:39 -05:00
pub ignore : Vec < String > ,
pub include : Vec < String > ,
2024-01-08 12:18:42 -05:00
}
2024-07-03 20:54:33 -04:00
impl FileFlags {
pub fn as_file_patterns (
& self ,
base : & Path ,
) -> Result < FilePatterns , AnyError > {
Ok ( FilePatterns {
include : if self . include . is_empty ( ) {
None
} else {
Some ( PathOrPatternSet ::from_include_relative_path_or_patterns (
base ,
& self . include ,
) ? )
} ,
exclude : PathOrPatternSet ::from_exclude_relative_path_or_patterns (
base ,
& self . ignore ,
) ? ,
base : base . to_path_buf ( ) ,
} )
}
}
2024-02-29 14:12:04 -05:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
pub struct AddFlags {
pub packages : Vec < String > ,
}
2024-08-12 16:17:25 -04:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
pub struct RemoveFlags {
pub packages : Vec < String > ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
pub struct BenchFlags {
pub files : FileFlags ,
2022-03-11 17:07:02 -05:00
pub filter : Option < String > ,
2023-02-12 12:40:45 -05:00
pub json : bool ,
2023-03-26 10:55:58 -04:00
pub no_run : bool ,
2023-06-15 13:09:37 -04:00
pub watch : Option < WatchFlags > ,
2022-03-11 17:07:02 -05:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct CacheFlags {
pub files : Vec < String > ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2022-04-10 19:12:51 -04:00
pub struct CheckFlags {
pub files : Vec < String > ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct CompileFlags {
pub source_file : String ,
2024-03-14 19:53:46 -04:00
pub output : Option < String > ,
2021-09-03 19:33:35 -04:00
pub args : Vec < String > ,
pub target : Option < String > ,
2023-07-28 11:46:26 -04:00
pub no_terminal : bool ,
2024-08-15 00:42:23 -04:00
pub icon : Option < String > ,
2023-03-18 19:43:07 -04:00
pub include : Vec < String > ,
2021-09-03 19:33:35 -04:00
}
2023-07-29 08:06:47 -04:00
impl CompileFlags {
pub fn resolve_target ( & self ) -> String {
self
. target
. clone ( )
. unwrap_or_else ( | | env! ( " TARGET " ) . to_string ( ) )
}
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct CompletionsFlags {
pub buf : Box < [ u8 ] > ,
}
2023-12-18 05:48:45 -05:00
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
2023-12-08 02:54:52 -05:00
pub enum CoverageType {
2023-12-18 05:48:45 -05:00
#[ default ]
2023-12-11 22:42:57 -05:00
Summary ,
2023-12-12 06:53:41 -05:00
Detailed ,
2023-12-08 02:54:52 -05:00
Lcov ,
Html ,
}
2023-12-18 05:48:45 -05:00
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
2021-09-03 19:33:35 -04:00
pub struct CoverageFlags {
2023-01-13 16:56:29 -05:00
pub files : FileFlags ,
2024-03-14 19:53:46 -04:00
pub output : Option < String > ,
2021-09-03 19:33:35 -04:00
pub include : Vec < String > ,
pub exclude : Vec < String > ,
2023-12-08 02:54:52 -05:00
pub r#type : CoverageType ,
2021-09-03 19:33:35 -04:00
}
2023-01-14 12:39:56 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub enum DocSourceFileFlag {
Builtin ,
2023-10-30 18:58:57 -04:00
Paths ( Vec < String > ) ,
2023-01-14 12:39:56 -05:00
}
impl Default for DocSourceFileFlag {
fn default ( ) -> Self {
Self ::Builtin
}
}
2023-11-01 11:25:05 -04:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct DocHtmlFlag {
2024-04-24 16:34:21 -04:00
pub name : Option < String > ,
2024-06-28 08:03:51 -04:00
pub category_docs_path : Option < String > ,
pub symbol_redirect_map_path : Option < String > ,
pub default_symbol_map_path : Option < String > ,
pub strip_trailing_html : bool ,
2024-03-14 19:53:46 -04:00
pub output : String ,
2023-11-01 11:25:05 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct DocFlags {
pub private : bool ,
pub json : bool ,
2023-10-31 18:19:42 -04:00
pub lint : bool ,
2023-11-01 11:25:05 -04:00
pub html : Option < DocHtmlFlag > ,
2023-10-30 18:58:57 -04:00
pub source_files : DocSourceFileFlag ,
2021-09-03 19:33:35 -04:00
pub filter : Option < String > ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct EvalFlags {
pub print : bool ,
pub code : String ,
}
2024-07-03 20:54:33 -04:00
#[ derive(Clone, Default, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct FmtFlags {
pub check : bool ,
2023-01-07 15:22:09 -05:00
pub files : FileFlags ,
2021-09-13 16:06:45 -04:00
pub use_tabs : Option < bool > ,
pub line_width : Option < NonZeroU32 > ,
pub indent_width : Option < NonZeroU8 > ,
pub single_quote : Option < bool > ,
pub prose_wrap : Option < String > ,
2023-01-25 15:06:00 -05:00
pub no_semicolons : Option < bool > ,
2023-06-15 13:09:37 -04:00
pub watch : Option < WatchFlags > ,
2024-08-09 12:52:23 -04:00
pub unstable_css : bool ,
2024-08-14 16:58:48 -04:00
pub unstable_html : bool ,
pub unstable_component : bool ,
2024-08-02 09:52:48 -04:00
pub unstable_yaml : bool ,
2021-09-03 19:33:35 -04:00
}
2023-06-14 18:29:19 -04:00
impl FmtFlags {
pub fn is_stdin ( & self ) -> bool {
let args = & self . files . include ;
2024-01-15 19:15:39 -05:00
args . len ( ) = = 1 & & args [ 0 ] = = " - "
2023-06-14 18:29:19 -04:00
}
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2022-08-19 19:37:05 -04:00
pub struct InitFlags {
pub dir : Option < String > ,
2024-07-09 21:13:34 -04:00
pub lib : bool ,
2024-08-08 12:54:39 -04:00
pub serve : bool ,
2022-08-19 19:37:05 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct InfoFlags {
pub json : bool ,
pub file : Option < String > ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2024-04-04 10:40:54 -04:00
pub struct InstallFlagsGlobal {
2021-09-03 19:33:35 -04:00
pub module_url : String ,
pub args : Vec < String > ,
pub name : Option < String > ,
2023-11-13 09:44:01 -05:00
pub root : Option < String > ,
2021-09-03 19:33:35 -04:00
pub force : bool ,
2024-04-04 10:40:54 -04:00
}
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub enum InstallKind {
#[ allow(unused) ]
2024-05-08 15:34:46 -04:00
Local ( Option < AddFlags > ) ,
2024-04-04 10:40:54 -04:00
Global ( InstallFlagsGlobal ) ,
}
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct InstallFlags {
2024-03-27 18:45:57 -04:00
pub global : bool ,
2024-04-04 10:40:54 -04:00
pub kind : InstallKind ,
2021-09-03 19:33:35 -04:00
}
2024-08-12 11:55:33 -04:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct JSONReferenceFlags {
pub json : deno_core ::serde_json ::Value ,
}
2023-09-15 20:42:09 -04:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct JupyterFlags {
pub install : bool ,
pub kernel : bool ,
2024-03-14 19:53:46 -04:00
pub conn_file : Option < String > ,
2023-09-15 20:42:09 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2024-04-04 10:40:54 -04:00
pub struct UninstallFlagsGlobal {
2021-09-30 11:38:07 -04:00
pub name : String ,
2023-11-13 09:44:01 -05:00
pub root : Option < String > ,
2024-04-04 10:40:54 -04:00
}
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub enum UninstallKind {
#[ allow(unused) ]
Local ,
Global ( UninstallFlagsGlobal ) ,
}
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct UninstallFlags {
2024-03-27 18:45:57 -04:00
pub global : bool ,
2024-04-04 10:40:54 -04:00
pub kind : UninstallKind ,
2021-09-30 11:38:07 -04:00
}
2024-07-03 20:54:33 -04:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct LintFlags {
2023-01-07 15:22:09 -05:00
pub files : FileFlags ,
2021-09-03 19:33:35 -04:00
pub rules : bool ,
2024-03-21 17:18:59 -04:00
pub fix : bool ,
2021-11-04 11:12:12 -04:00
pub maybe_rules_tags : Option < Vec < String > > ,
pub maybe_rules_include : Option < Vec < String > > ,
pub maybe_rules_exclude : Option < Vec < String > > ,
2021-09-03 19:33:35 -04:00
pub json : bool ,
2022-09-28 12:47:48 -04:00
pub compact : bool ,
2023-06-15 13:09:37 -04:00
pub watch : Option < WatchFlags > ,
2024-08-19 16:42:13 -04:00
pub ext : Option < String > ,
2021-09-03 19:33:35 -04:00
}
2023-06-14 18:29:19 -04:00
impl LintFlags {
pub fn is_stdin ( & self ) -> bool {
let args = & self . files . include ;
2024-01-15 19:15:39 -05:00
args . len ( ) = = 1 & & args [ 0 ] = = " - "
2023-06-14 18:29:19 -04:00
}
}
2024-03-13 12:07:24 -04:00
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
2021-09-03 19:33:35 -04:00
pub struct ReplFlags {
2022-04-20 08:16:37 -04:00
pub eval_files : Option < Vec < String > > ,
2021-09-03 19:33:35 -04:00
pub eval : Option < String > ,
2022-12-07 14:21:18 -05:00
pub is_default_command : bool ,
2021-09-03 19:33:35 -04:00
}
2023-11-14 16:06:00 -05:00
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
2021-09-03 19:33:35 -04:00
pub struct RunFlags {
pub script : String ,
2023-06-15 13:09:37 -04:00
pub watch : Option < WatchFlagsWithPaths > ,
2024-08-12 11:55:33 -04:00
pub bare : bool ,
2021-09-03 19:33:35 -04:00
}
2022-08-12 15:21:17 -04:00
impl RunFlags {
2023-12-06 16:36:06 -05:00
#[ cfg(test) ]
pub fn new_default ( script : String ) -> Self {
Self {
script ,
watch : None ,
2024-08-12 11:55:33 -04:00
bare : false ,
2023-12-06 16:36:06 -05:00
}
}
2022-08-12 15:21:17 -04:00
pub fn is_stdin ( & self ) -> bool {
self . script = = " - "
}
}
2024-04-24 15:45:49 -04:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct ServeFlags {
pub script : String ,
pub watch : Option < WatchFlagsWithPaths > ,
2024-05-17 01:38:50 -04:00
pub port : u16 ,
2024-04-24 15:45:49 -04:00
pub host : String ,
2024-08-14 18:26:21 -04:00
pub worker_count : Option < usize > ,
2024-04-24 15:45:49 -04:00
}
impl ServeFlags {
#[ cfg(test) ]
pub fn new_default ( script : String , port : u16 , host : & str ) -> Self {
Self {
script ,
watch : None ,
2024-05-17 01:38:50 -04:00
port ,
2024-04-24 15:45:49 -04:00
host : host . to_owned ( ) ,
2024-08-14 18:26:21 -04:00
worker_count : None ,
2024-04-24 15:45:49 -04:00
}
}
}
2023-06-15 13:09:37 -04:00
#[ derive(Clone, Default, Debug, Eq, PartialEq) ]
pub struct WatchFlags {
2023-10-30 20:25:58 -04:00
pub hmr : bool ,
2023-06-15 13:09:37 -04:00
pub no_clear_screen : bool ,
2024-03-27 18:47:46 -04:00
pub exclude : Vec < String > ,
2023-06-15 13:09:37 -04:00
}
#[ derive(Clone, Default, Debug, Eq, PartialEq) ]
pub struct WatchFlagsWithPaths {
2023-10-30 20:25:58 -04:00
pub hmr : bool ,
2024-03-14 19:53:46 -04:00
pub paths : Vec < String > ,
2023-06-15 13:09:37 -04:00
pub no_clear_screen : bool ,
2024-03-27 18:47:46 -04:00
pub exclude : Vec < String > ,
2023-06-15 13:09:37 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2022-03-10 20:56:14 -05:00
pub struct TaskFlags {
2022-06-08 17:30:16 -04:00
pub cwd : Option < String > ,
2023-02-22 22:45:35 -05:00
pub task : Option < String > ,
2024-08-21 09:54:59 -04:00
pub is_run : bool ,
2022-03-10 20:56:14 -05:00
}
2024-07-03 20:54:33 -04:00
#[ derive(Clone, Copy, Debug, Default, Eq, PartialEq) ]
2023-08-02 12:38:10 -04:00
pub enum TestReporterConfig {
#[ default ]
Pretty ,
Dot ,
2023-08-02 22:05:34 -04:00
Junit ,
2023-08-25 19:19:23 -04:00
Tap ,
2023-08-02 12:38:10 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Default, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct TestFlags {
pub doc : bool ,
pub no_run : bool ,
2023-06-15 13:09:37 -04:00
pub coverage_dir : Option < String > ,
2024-05-22 23:04:12 -04:00
pub clean : bool ,
2021-09-03 19:33:35 -04:00
pub fail_fast : Option < NonZeroUsize > ,
2023-01-07 15:22:09 -05:00
pub files : FileFlags ,
2024-09-02 18:06:27 -04:00
pub permit_no_files : bool ,
2021-09-03 19:33:35 -04:00
pub filter : Option < String > ,
pub shuffle : Option < u64 > ,
2023-01-07 15:22:09 -05:00
pub concurrent_jobs : Option < NonZeroUsize > ,
2024-02-28 11:12:43 -05:00
pub trace_leaks : bool ,
2024-08-19 13:09:51 -04:00
pub watch : Option < WatchFlagsWithPaths > ,
2023-08-02 12:38:10 -04:00
pub reporter : TestReporterConfig ,
2023-08-02 22:05:34 -04:00
pub junit_path : Option < String > ,
2024-08-19 21:27:36 -04:00
pub hide_stacktraces : bool ,
2021-09-03 19:33:35 -04:00
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2021-09-03 19:33:35 -04:00
pub struct UpgradeFlags {
pub dry_run : bool ,
pub force : bool ,
2024-08-12 14:32:53 -04:00
pub release_candidate : bool ,
2021-09-03 19:33:35 -04:00
pub canary : bool ,
pub version : Option < String > ,
2024-03-14 19:53:46 -04:00
pub output : Option < String > ,
2024-08-19 11:05:10 -04:00
pub version_or_hash_or_channel : Option < String > ,
2021-09-03 19:33:35 -04:00
}
2023-11-23 18:38:07 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct PublishFlags {
pub token : Option < String > ,
2024-01-11 16:17:03 -05:00
pub dry_run : bool ,
2024-02-19 10:28:41 -05:00
pub allow_slow_types : bool ,
2024-03-07 16:13:36 -05:00
pub allow_dirty : bool ,
2024-02-29 11:18:47 -05:00
pub no_provenance : bool ,
2023-11-23 18:38:07 -05:00
}
2024-08-12 11:55:33 -04:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub struct HelpFlags {
pub help : clap ::builder ::StyledStr ,
}
2023-01-07 15:22:09 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
2019-11-26 11:06:32 -05:00
pub enum DenoSubcommand {
2024-02-29 14:12:04 -05:00
Add ( AddFlags ) ,
2024-08-12 16:17:25 -04:00
Remove ( RemoveFlags ) ,
2022-03-11 17:07:02 -05:00
Bench ( BenchFlags ) ,
2024-09-02 11:27:37 -04:00
Bundle ,
2021-09-03 19:33:35 -04:00
Cache ( CacheFlags ) ,
2022-04-10 19:12:51 -04:00
Check ( CheckFlags ) ,
2024-08-08 09:22:18 -04:00
Clean ,
2021-09-03 19:33:35 -04:00
Compile ( CompileFlags ) ,
Completions ( CompletionsFlags ) ,
Coverage ( CoverageFlags ) ,
Doc ( DocFlags ) ,
Eval ( EvalFlags ) ,
Fmt ( FmtFlags ) ,
2022-08-19 19:37:05 -04:00
Init ( InitFlags ) ,
2021-09-03 19:33:35 -04:00
Info ( InfoFlags ) ,
Install ( InstallFlags ) ,
2024-08-12 11:55:33 -04:00
JSONReference ( JSONReferenceFlags ) ,
2023-09-15 20:42:09 -04:00
Jupyter ( JupyterFlags ) ,
2021-09-30 11:38:07 -04:00
Uninstall ( UninstallFlags ) ,
2021-06-22 21:48:01 -04:00
Lsp ,
2021-09-03 19:33:35 -04:00
Lint ( LintFlags ) ,
Repl ( ReplFlags ) ,
Run ( RunFlags ) ,
2024-04-24 15:45:49 -04:00
Serve ( ServeFlags ) ,
2022-03-10 20:56:14 -05:00
Task ( TaskFlags ) ,
2021-09-03 19:33:35 -04:00
Test ( TestFlags ) ,
2019-11-26 11:06:32 -05:00
Types ,
2021-09-03 19:33:35 -04:00
Upgrade ( UpgradeFlags ) ,
2024-09-03 03:00:57 -04:00
Vendor ,
2023-11-23 18:38:07 -05:00
Publish ( PublishFlags ) ,
2024-08-12 11:55:33 -04:00
Help ( HelpFlags ) ,
2019-11-26 11:06:32 -05:00
}
2023-11-11 12:01:48 -05:00
impl DenoSubcommand {
pub fn is_run ( & self ) -> bool {
matches! ( self , Self ::Run ( _ ) )
}
2023-11-14 16:06:00 -05:00
2023-11-24 22:46:16 -05:00
// Returns `true` if the subcommand depends on testing infrastructure.
pub fn needs_test ( & self ) -> bool {
matches! (
self ,
Self ::Test ( _ )
| Self ::Jupyter ( _ )
| Self ::Repl ( _ )
| Self ::Bench ( _ )
| Self ::Lsp
)
2023-11-14 16:06:00 -05:00
}
2023-11-11 12:01:48 -05:00
}
2019-11-26 11:06:32 -05:00
impl Default for DenoSubcommand {
fn default ( ) -> DenoSubcommand {
2022-04-20 08:16:37 -04:00
DenoSubcommand ::Repl ( ReplFlags {
eval_files : None ,
eval : None ,
2022-12-07 14:21:18 -05:00
is_default_command : true ,
2022-04-20 08:16:37 -04:00
} )
2019-11-26 11:06:32 -05:00
}
2018-08-17 16:34:30 -04:00
}
2022-09-19 04:25:03 -04:00
#[ derive(Debug, Clone, Copy, Eq, PartialEq) ]
2022-04-10 19:12:51 -04:00
pub enum TypeCheckMode {
2022-06-18 12:11:15 -04:00
/// Type-check all modules.
2021-11-29 17:23:30 -05:00
All ,
2022-06-18 12:11:15 -04:00
/// Skip type-checking of all modules. The default value for "deno run" and
2022-06-13 17:13:16 -04:00
/// several other subcommands.
2021-11-29 17:23:30 -05:00
None ,
2022-06-18 12:11:15 -04:00
/// Only type-check local modules. The default value for "deno test" and
2022-06-13 17:13:16 -04:00
/// several other subcommands.
2021-11-29 17:23:30 -05:00
Local ,
}
2023-06-07 10:09:10 -04:00
impl TypeCheckMode {
/// Gets if type checking will occur under this mode.
pub fn is_true ( & self ) -> bool {
match self {
Self ::None = > false ,
Self ::Local | Self ::All = > true ,
}
}
/// Gets the corresponding module `GraphKind` that should be created
/// for the current `TypeCheckMode`.
pub fn as_graph_kind ( & self ) -> GraphKind {
match self . is_true ( ) {
true = > GraphKind ::All ,
false = > GraphKind ::CodeOnly ,
}
}
}
2022-04-10 19:12:51 -04:00
impl Default for TypeCheckMode {
2021-11-29 17:23:30 -05:00
fn default ( ) -> Self {
2022-06-13 17:13:16 -04:00
Self ::None
2022-04-10 19:12:51 -04:00
}
}
2023-01-17 19:18:24 -05:00
#[ derive(Clone, Debug, Eq, PartialEq) ]
pub enum CaData {
/// The string is a file path
File ( String ) ,
/// This variant is not exposed as an option in the CLI, it is used internally
/// for standalone binaries.
Bytes ( Vec < u8 > ) ,
}
2024-07-09 23:06:08 -04:00
// Info needed to run NPM lifecycle scripts
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
pub struct LifecycleScriptsConfig {
pub allowed : PackagesAllowedScripts ,
pub initial_cwd : Option < PathBuf > ,
}
#[ derive(Debug, Clone, Eq, PartialEq, Default) ]
/// The set of npm packages that are allowed to run lifecycle scripts.
pub enum PackagesAllowedScripts {
All ,
Some ( Vec < String > ) ,
#[ default ]
None ,
}
fn parse_packages_allowed_scripts ( s : & str ) -> Result < String , AnyError > {
if ! s . starts_with ( " npm: " ) {
bail! ( " Invalid package for --allow-scripts: '{}'. An 'npm:' specifier is required " , s ) ;
} else {
Ok ( s . into ( ) )
}
}
2024-01-22 12:37:28 -05:00
#[ derive(
Clone , Default , Debug , Eq , PartialEq , serde ::Serialize , serde ::Deserialize ,
) ]
pub struct UnstableConfig {
pub legacy_flag_enabled : bool , // --unstable
pub bare_node_builtins : bool , // --unstable-bare-node-builts
pub sloppy_imports : bool ,
pub features : Vec < String > , // --unstabe-kv --unstable-cron
}
2022-09-19 04:25:03 -04:00
#[ derive(Clone, Debug, Eq, PartialEq, Default) ]
2020-02-26 05:52:15 -05:00
pub struct Flags {
2019-12-03 17:23:10 -05:00
/// Vector of CLI arguments - these are user script arguments, all Deno
/// specific flags are removed.
2019-11-26 11:06:32 -05:00
pub argv : Vec < String > ,
pub subcommand : DenoSubcommand ,
2024-08-20 10:55:47 -04:00
pub frozen_lockfile : Option < bool > ,
2021-08-07 08:49:38 -04:00
pub ca_stores : Option < Vec < String > > ,
2023-01-17 19:18:24 -05:00
pub ca_data : Option < CaData > ,
2021-07-23 10:31:16 -04:00
pub cache_blocklist : Vec < String > ,
2021-07-27 17:25:09 -04:00
/// This is not exposed as an option in the CLI, it is used internally when
/// the language server is configured with an explicit cache option.
pub cache_path : Option < PathBuf > ,
2019-12-03 17:48:53 -05:00
pub cached_only : bool ,
2022-04-10 19:12:51 -04:00
pub type_check_mode : TypeCheckMode ,
2022-05-13 11:40:50 -04:00
pub config_flag : ConfigFlag ,
2024-08-30 17:58:24 -04:00
pub node_modules_dir : Option < NodeModulesDirMode > ,
2023-08-06 21:56:56 -04:00
pub vendor : Option < bool > ,
2023-11-05 16:27:36 -05:00
pub enable_op_summary_metrics : bool ,
2021-07-23 10:31:16 -04:00
pub enable_testing_features : bool ,
2023-03-22 10:15:53 -04:00
pub ext : Option < String > ,
2024-03-14 19:53:46 -04:00
pub ignore : Vec < String > ,
2020-04-30 11:23:40 -04:00
pub import_map_path : Option < String > ,
2023-11-01 11:21:13 -04:00
pub env_file : Option < String > ,
2020-04-03 13:40:11 -04:00
pub inspect_brk : Option < SocketAddr > ,
2022-12-12 09:33:30 -05:00
pub inspect_wait : Option < SocketAddr > ,
2021-07-23 10:31:16 -04:00
pub inspect : Option < SocketAddr > ,
pub location : Option < Url > ,
2024-03-14 19:53:46 -04:00
pub lock : Option < String > ,
2020-04-30 11:23:40 -04:00
pub log_level : Option < Level > ,
pub no_remote : bool ,
2022-11-03 11:42:56 -04:00
pub no_lock : bool ,
2022-09-07 09:33:51 -04:00
pub no_npm : bool ,
2020-04-30 11:23:40 -04:00
pub reload : bool ,
pub seed : Option < u64 > ,
2023-11-10 12:41:24 -05:00
pub strace_ops : Option < Vec < String > > ,
2024-01-22 12:37:28 -05:00
pub unstable_config : UnstableConfig ,
2021-08-10 07:19:45 -04:00
pub unsafely_ignore_certificate_errors : Option < Vec < String > > ,
2020-12-06 12:19:21 -05:00
pub v8_flags : Vec < String > ,
2024-04-17 10:19:55 -04:00
pub code_cache_enabled : bool ,
2024-05-06 19:21:58 -04:00
pub permissions : PermissionFlags ,
2024-07-09 23:06:08 -04:00
pub allow_scripts : PackagesAllowedScripts ,
2024-05-06 19:21:58 -04:00
}
#[ derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize) ]
pub struct PermissionFlags {
pub allow_all : bool ,
pub allow_env : Option < Vec < String > > ,
pub deny_env : Option < Vec < String > > ,
pub allow_ffi : Option < Vec < String > > ,
pub deny_ffi : Option < Vec < String > > ,
pub allow_net : Option < Vec < String > > ,
pub deny_net : Option < Vec < String > > ,
pub allow_read : Option < Vec < String > > ,
pub deny_read : Option < Vec < String > > ,
pub allow_run : Option < Vec < String > > ,
pub deny_run : Option < Vec < String > > ,
pub allow_sys : Option < Vec < String > > ,
pub deny_sys : Option < Vec < String > > ,
pub allow_write : Option < Vec < String > > ,
pub deny_write : Option < Vec < String > > ,
pub no_prompt : bool ,
}
impl PermissionFlags {
pub fn has_permission ( & self ) -> bool {
self . allow_all
| | self . allow_env . is_some ( )
| | self . deny_env . is_some ( )
| | self . allow_ffi . is_some ( )
| | self . deny_ffi . is_some ( )
| | self . allow_net . is_some ( )
| | self . deny_net . is_some ( )
| | self . allow_read . is_some ( )
| | self . deny_read . is_some ( )
| | self . allow_run . is_some ( )
| | self . deny_run . is_some ( )
| | self . allow_sys . is_some ( )
| | self . deny_sys . is_some ( )
| | self . allow_write . is_some ( )
| | self . deny_write . is_some ( )
}
pub fn to_options (
& self ,
// will be None when `deno compile` can't resolve the cwd
initial_cwd : Option < & Path > ,
) -> Result < PermissionsOptions , AnyError > {
fn convert_option_str_to_path_buf (
flag : & Option < Vec < String > > ,
initial_cwd : Option < & Path > ,
) -> Result < Option < Vec < PathBuf > > , AnyError > {
let Some ( paths ) = & flag else {
return Ok ( None ) ;
} ;
let mut new_paths = Vec ::with_capacity ( paths . len ( ) ) ;
for path in paths {
if let Some ( initial_cwd ) = initial_cwd {
new_paths . push ( initial_cwd . join ( path ) )
} else {
let path = PathBuf ::from ( path ) ;
if path . is_absolute ( ) {
new_paths . push ( path ) ;
} else {
bail! ( " Could not resolve relative permission path '{}' when current working directory could not be resolved. " , path . display ( ) )
}
}
}
Ok ( Some ( new_paths ) )
}
Ok ( PermissionsOptions {
allow_all : self . allow_all ,
allow_env : self . allow_env . clone ( ) ,
deny_env : self . deny_env . clone ( ) ,
allow_net : self . allow_net . clone ( ) ,
deny_net : self . deny_net . clone ( ) ,
allow_ffi : convert_option_str_to_path_buf ( & self . allow_ffi , initial_cwd ) ? ,
deny_ffi : convert_option_str_to_path_buf ( & self . deny_ffi , initial_cwd ) ? ,
allow_read : convert_option_str_to_path_buf (
& self . allow_read ,
initial_cwd ,
) ? ,
deny_read : convert_option_str_to_path_buf ( & self . deny_read , initial_cwd ) ? ,
allow_run : self . allow_run . clone ( ) ,
deny_run : self . deny_run . clone ( ) ,
allow_sys : self . allow_sys . clone ( ) ,
deny_sys : self . deny_sys . clone ( ) ,
allow_write : convert_option_str_to_path_buf (
& self . allow_write ,
initial_cwd ,
) ? ,
deny_write : convert_option_str_to_path_buf (
& self . deny_write ,
initial_cwd ,
) ? ,
prompt : ! resolve_no_prompt ( self ) ,
} )
}
2018-11-15 12:56:17 -05:00
}
2024-03-14 19:53:46 -04:00
fn join_paths ( allowlist : & [ String ] , d : & str ) -> String {
2020-06-13 13:09:39 -04:00
allowlist
2020-02-11 04:29:36 -05:00
. iter ( )
2024-03-14 19:53:46 -04:00
. map ( | path | path . to_string ( ) )
2020-02-11 04:29:36 -05:00
. collect ::< Vec < String > > ( )
. join ( d )
}
2020-02-26 05:52:15 -05:00
impl Flags {
2020-01-30 18:42:39 -05:00
/// Return list of permission arguments that are equivalent
/// to the ones used to create `self`.
pub fn to_permission_args ( & self ) -> Vec < String > {
let mut args = vec! [ ] ;
2024-05-06 19:21:58 -04:00
if self . permissions . allow_all {
2022-01-10 09:22:03 -05:00
args . push ( " --allow-all " . to_string ( ) ) ;
return args ;
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_read {
2020-12-29 13:34:35 -05:00
Some ( read_allowlist ) if read_allowlist . is_empty ( ) = > {
args . push ( " --allow-read " . to_string ( ) ) ;
}
Some ( read_allowlist ) = > {
let s = format! ( " --allow-read= {} " , join_paths ( read_allowlist , " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_read {
2023-08-03 07:19:19 -04:00
Some ( read_denylist ) if read_denylist . is_empty ( ) = > {
args . push ( " --deny-read " . to_string ( ) ) ;
}
Some ( read_denylist ) = > {
let s = format! ( " --deny-read= {} " , join_paths ( read_denylist , " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_write {
2020-12-29 13:34:35 -05:00
Some ( write_allowlist ) if write_allowlist . is_empty ( ) = > {
args . push ( " --allow-write " . to_string ( ) ) ;
}
Some ( write_allowlist ) = > {
let s = format! ( " --allow-write= {} " , join_paths ( write_allowlist , " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_write {
2023-08-03 07:19:19 -04:00
Some ( write_denylist ) if write_denylist . is_empty ( ) = > {
args . push ( " --deny-write " . to_string ( ) ) ;
}
Some ( write_denylist ) = > {
let s = format! ( " --deny-write= {} " , join_paths ( write_denylist , " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_net {
2020-12-29 13:34:35 -05:00
Some ( net_allowlist ) if net_allowlist . is_empty ( ) = > {
args . push ( " --allow-net " . to_string ( ) ) ;
}
Some ( net_allowlist ) = > {
let s = format! ( " --allow-net= {} " , net_allowlist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_net {
2023-08-03 07:19:19 -04:00
Some ( net_denylist ) if net_denylist . is_empty ( ) = > {
args . push ( " --deny-net " . to_string ( ) ) ;
}
Some ( net_denylist ) = > {
let s = format! ( " --deny-net= {} " , net_denylist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2021-08-10 07:19:45 -04:00
match & self . unsafely_ignore_certificate_errors {
2021-08-09 10:53:21 -04:00
Some ( ic_allowlist ) if ic_allowlist . is_empty ( ) = > {
2021-08-10 08:19:42 -04:00
args . push ( " --unsafely-ignore-certificate-errors " . to_string ( ) ) ;
2021-08-09 10:53:21 -04:00
}
Some ( ic_allowlist ) = > {
let s = format! (
2021-08-10 08:19:42 -04:00
" --unsafely-ignore-certificate-errors={} " ,
2021-08-09 10:53:21 -04:00
ic_allowlist . join ( " , " )
) ;
args . push ( s ) ;
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_env {
2021-04-13 07:25:21 -04:00
Some ( env_allowlist ) if env_allowlist . is_empty ( ) = > {
args . push ( " --allow-env " . to_string ( ) ) ;
}
Some ( env_allowlist ) = > {
let s = format! ( " --allow-env= {} " , env_allowlist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_env {
2023-08-03 07:19:19 -04:00
Some ( env_denylist ) if env_denylist . is_empty ( ) = > {
args . push ( " --deny-env " . to_string ( ) ) ;
}
Some ( env_denylist ) = > {
let s = format! ( " --deny-env= {} " , env_denylist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_run {
2021-04-09 18:12:00 -04:00
Some ( run_allowlist ) if run_allowlist . is_empty ( ) = > {
args . push ( " --allow-run " . to_string ( ) ) ;
}
Some ( run_allowlist ) = > {
let s = format! ( " --allow-run= {} " , run_allowlist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_run {
2023-08-03 07:19:19 -04:00
Some ( run_denylist ) if run_denylist . is_empty ( ) = > {
args . push ( " --deny-run " . to_string ( ) ) ;
}
Some ( run_denylist ) = > {
let s = format! ( " --deny-run= {} " , run_denylist . join ( " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_sys {
2022-09-28 08:46:50 -04:00
Some ( sys_allowlist ) if sys_allowlist . is_empty ( ) = > {
args . push ( " --allow-sys " . to_string ( ) ) ;
}
Some ( sys_allowlist ) = > {
let s = format! ( " --allow-sys= {} " , sys_allowlist . join ( " , " ) ) ;
args . push ( s )
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_sys {
2023-08-03 07:19:19 -04:00
Some ( sys_denylist ) if sys_denylist . is_empty ( ) = > {
args . push ( " --deny-sys " . to_string ( ) ) ;
}
Some ( sys_denylist ) = > {
let s = format! ( " --deny-sys= {} " , sys_denylist . join ( " , " ) ) ;
args . push ( s )
}
_ = > { }
}
2024-05-06 19:21:58 -04:00
match & self . permissions . allow_ffi {
2021-08-06 17:28:10 -04:00
Some ( ffi_allowlist ) if ffi_allowlist . is_empty ( ) = > {
args . push ( " --allow-ffi " . to_string ( ) ) ;
}
Some ( ffi_allowlist ) = > {
2021-10-13 13:04:44 -04:00
let s = format! ( " --allow-ffi= {} " , join_paths ( ffi_allowlist , " , " ) ) ;
2021-08-06 17:28:10 -04:00
args . push ( s ) ;
}
_ = > { }
2020-01-30 18:42:39 -05:00
}
2024-05-06 19:21:58 -04:00
match & self . permissions . deny_ffi {
2023-08-03 07:19:19 -04:00
Some ( ffi_denylist ) if ffi_denylist . is_empty ( ) = > {
args . push ( " --deny-ffi " . to_string ( ) ) ;
}
Some ( ffi_denylist ) = > {
let s = format! ( " --deny-ffi= {} " , join_paths ( ffi_denylist , " , " ) ) ;
args . push ( s ) ;
}
_ = > { }
}
2020-01-30 18:42:39 -05:00
args
}
2022-01-17 20:10:17 -05:00
2024-07-08 10:12:10 -04:00
/// Extract the paths the config file should be discovered from.
2024-07-03 20:54:33 -04:00
///
/// Returns `None` if the config file should not be auto-discovered.
2023-03-13 21:12:09 -04:00
pub fn config_path_args ( & self , current_dir : & Path ) -> Option < Vec < PathBuf > > {
2024-07-03 20:54:33 -04:00
fn resolve_multiple_files (
2024-07-08 10:12:10 -04:00
files_or_dirs : & [ String ] ,
2024-07-03 20:54:33 -04:00
current_dir : & Path ,
) -> Vec < PathBuf > {
2024-07-08 10:12:10 -04:00
let mut seen = HashSet ::with_capacity ( files_or_dirs . len ( ) ) ;
let result = files_or_dirs
2024-07-03 20:54:33 -04:00
. iter ( )
. filter_map ( | p | {
2024-07-08 10:12:10 -04:00
let path = normalize_path ( current_dir . join ( p ) ) ;
if seen . insert ( path . clone ( ) ) {
2024-07-03 20:54:33 -04:00
Some ( path )
} else {
None
}
} )
. collect ::< Vec < _ > > ( ) ;
if result . is_empty ( ) {
vec! [ current_dir . to_path_buf ( ) ]
} else {
result
}
}
2023-01-14 23:06:46 -05:00
2024-07-03 20:54:33 -04:00
use DenoSubcommand ::* ;
2023-01-14 23:06:46 -05:00
match & self . subcommand {
2024-01-15 19:15:39 -05:00
Fmt ( FmtFlags { files , .. } ) = > {
2024-07-03 20:54:33 -04:00
Some ( resolve_multiple_files ( & files . include , current_dir ) )
2024-01-15 19:15:39 -05:00
}
Lint ( LintFlags { files , .. } ) = > {
2024-07-03 20:54:33 -04:00
Some ( resolve_multiple_files ( & files . include , current_dir ) )
2024-01-15 19:15:39 -05:00
}
2024-07-03 20:54:33 -04:00
Run ( RunFlags { script , .. } )
| Compile ( CompileFlags {
source_file : script ,
..
} ) = > {
2023-03-13 21:12:09 -04:00
if let Ok ( module_specifier ) = resolve_url_or_path ( script , current_dir ) {
2023-01-14 23:06:46 -05:00
if module_specifier . scheme ( ) = = " file "
| | module_specifier . scheme ( ) = = " npm "
{
if let Ok ( p ) = module_specifier . to_file_path ( ) {
2024-07-03 20:54:33 -04:00
Some ( vec! [ p . parent ( ) . unwrap ( ) . to_path_buf ( ) ] )
2023-01-14 23:06:46 -05:00
} else {
2024-07-03 20:54:33 -04:00
Some ( vec! [ current_dir . to_path_buf ( ) ] )
2023-01-14 23:06:46 -05:00
}
2022-02-25 00:39:18 -05:00
} else {
2023-01-14 23:06:46 -05:00
// When the entrypoint doesn't have file: scheme (it's the remote
// script), then we don't auto discover config file.
None
2022-02-25 00:39:18 -05:00
}
2022-01-17 20:10:17 -05:00
} else {
2024-07-03 20:54:33 -04:00
Some ( vec! [ current_dir . to_path_buf ( ) ] )
2022-01-17 20:10:17 -05:00
}
}
2023-02-23 10:58:10 -05:00
Task ( TaskFlags {
cwd : Some ( path ) , ..
} ) = > {
2024-01-15 19:15:39 -05:00
// todo(dsherret): Why is this canonicalized? Document why.
2023-02-23 10:58:10 -05:00
// attempt to resolve the config file from the task subcommand's
// `--cwd` when specified
match canonicalize_path ( & PathBuf ::from ( path ) ) {
Ok ( path ) = > Some ( vec! [ path ] ) ,
2024-07-03 20:54:33 -04:00
Err ( _ ) = > Some ( vec! [ current_dir . to_path_buf ( ) ] ) ,
2024-05-08 15:34:46 -04:00
}
}
2024-07-03 20:54:33 -04:00
_ = > Some ( vec! [ current_dir . to_path_buf ( ) ] ) ,
2023-02-20 13:14:06 -05:00
}
}
2022-11-23 22:00:31 -05:00
pub fn has_permission ( & self ) -> bool {
2024-05-06 19:21:58 -04:00
self . permissions . has_permission ( )
2022-11-23 22:00:31 -05:00
}
pub fn has_permission_in_argv ( & self ) -> bool {
self . argv . iter ( ) . any ( | arg | {
arg = = " --allow-all "
| | arg . starts_with ( " --allow-env " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-env " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-ffi " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-ffi " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-net " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-net " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-read " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-read " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-run " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-run " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-sys " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-sys " )
2022-11-23 22:00:31 -05:00
| | arg . starts_with ( " --allow-write " )
2023-08-03 07:19:19 -04:00
| | arg . starts_with ( " --deny-write " )
2022-11-23 22:00:31 -05:00
} )
}
2024-03-13 12:07:24 -04:00
#[ inline(always) ]
fn allow_all ( & mut self ) {
2024-05-06 19:21:58 -04:00
self . permissions . allow_all = true ;
self . permissions . allow_read = Some ( vec! [ ] ) ;
self . permissions . allow_env = Some ( vec! [ ] ) ;
self . permissions . allow_net = Some ( vec! [ ] ) ;
self . permissions . allow_run = Some ( vec! [ ] ) ;
self . permissions . allow_write = Some ( vec! [ ] ) ;
self . permissions . allow_sys = Some ( vec! [ ] ) ;
self . permissions . allow_ffi = Some ( vec! [ ] ) ;
2024-03-13 12:07:24 -04:00
}
2024-03-27 18:47:46 -04:00
pub fn resolve_watch_exclude_set (
& self ,
) -> Result < PathOrPatternSet , AnyError > {
if let DenoSubcommand ::Run ( RunFlags {
watch :
Some ( WatchFlagsWithPaths {
exclude : excluded_paths ,
..
} ) ,
..
} )
| DenoSubcommand ::Bench ( BenchFlags {
watch :
Some ( WatchFlags {
exclude : excluded_paths ,
..
} ) ,
..
} )
| DenoSubcommand ::Test ( TestFlags {
watch :
2024-08-19 13:09:51 -04:00
Some ( WatchFlagsWithPaths {
2024-03-27 18:47:46 -04:00
exclude : excluded_paths ,
..
} ) ,
..
} )
| DenoSubcommand ::Lint ( LintFlags {
watch :
Some ( WatchFlags {
exclude : excluded_paths ,
..
} ) ,
..
} )
| DenoSubcommand ::Fmt ( FmtFlags {
watch :
Some ( WatchFlags {
exclude : excluded_paths ,
..
} ) ,
..
} ) = & self . subcommand
{
let cwd = std ::env ::current_dir ( ) ? ;
PathOrPatternSet ::from_exclude_relative_path_or_patterns (
& cwd ,
excluded_paths ,
)
. context ( " Failed resolving watch exclude patterns. " )
} else {
Ok ( PathOrPatternSet ::default ( ) )
}
}
2020-12-29 13:34:35 -05:00
}
2024-08-21 09:54:59 -04:00
static ENV_VARIABLES_HELP : & str = cstr! (
2024-01-23 13:56:50 -05:00
r #" <y>Environment variables:</>
2024-08-12 11:55:33 -04:00
< g > DENO_AUTH_TOKENS < / > A semi - colon separated list of bearer tokens and hostnames
to use when fetching remote modules from private repositories
< p ( 245 ) > ( e . g . " abcde12345@deno.land;54321edcba@github.com " ) < / >
< g > DENO_CERT < / > Load certificate authorities from PEM encoded file
< g > DENO_DIR < / > Set the cache directory
< g > DENO_INSTALL_ROOT < / > Set deno install ' s output directory
< p ( 245 ) > ( defaults to $HOME / . deno / bin ) < / >
< g > DENO_NO_PACKAGE_JSON < / > Disables auto - resolution of package . json
< g > DENO_NO_UPDATE_CHECK < / > Set to disable checking if a newer Deno version is available
< g > DENO_TLS_CA_STORE < / > Comma - separated list of order dependent certificate stores .
Possible values : " system " , " mozilla " .
< p ( 245 ) > ( defaults to " mozilla " ) < / >
< g > HTTP_PROXY < / > Proxy address for HTTP requests
< p ( 245 ) > ( module downloads , fetch ) < / >
< g > HTTPS_PROXY < / > Proxy address for HTTPS requests
< p ( 245 ) > ( module downloads , fetch ) < / >
< g > NO_COLOR < / > Set to disable color
< g > NO_PROXY < / > Comma - separated list of hosts which do not use a proxy
< p ( 245 ) > ( module downloads , fetch ) < / >
< g > NPM_CONFIG_REGISTRY < / > URL to use for the npm registry . " #
2024-01-23 13:56:50 -05:00
) ;
2019-06-05 13:44:46 -04:00
2024-08-21 09:54:59 -04:00
static DENO_HELP : & str = cstr! (
2024-08-12 11:55:33 -04:00
" Deno: <g>A modern JavaScript and TypeScript runtime</>
< p ( 245 ) > Usage :< / > < g > { usage } < / >
< y > Commands :< / >
< y > Execution :< / >
< g > run < / > Run a JavaScript or TypeScript program , or a task
< p ( 245 ) > deno run main . ts | deno run - - allow - net = google . com main . ts | deno main . ts < / >
< g > serve < / > Run a server
< p ( 245 ) > deno serve main . ts < / >
< g > task < / > Run a task defined in the configuration file
< p ( 245 ) > deno task dev < / >
< g > repl < / > Start an interactive Read - Eval - Print Loop ( REPL ) for Deno
< g > eval < / > Evaluate a script from the command line
< y > Dependency management :< / >
< g > add < / > Add dependencies
< p ( 245 ) > deno add @ std / assert | deno add npm :express < / >
< g > install < / > Install script as an executable
< g > uninstall < / > Uninstall a script previously installed with deno install
2024-08-18 18:39:53 -04:00
< g > remove < / > Remove dependencies from the configuration file
2024-08-12 11:55:33 -04:00
< y > Tooling :< / >
< g > bench < / > Run benchmarks
< p ( 245 ) > deno bench bench . ts < / >
< g > cache < / > Cache the dependencies
< g > check < / > Type - check the dependencies
< g > compile < / > Compile the script into a self contained executable
< p ( 245 ) > deno compile main . ts | deno compile - - target = x86_64 - unknown - linux - gnu < / >
< g > coverage < / > Print coverage reports
< g > doc < / > Genereate and show documentation for a module or built - ins
< p ( 245 ) > deno doc | deno doc - - json | deno doc - - html mod . ts < / >
< g > fmt < / > Format source files
< p ( 245 ) > deno fmt | deno fmt main . ts < / >
< g > info < / > Show info about cache or info related to source file
< g > jupyter < / > Deno kernel for Jupyter notebooks
< g > lint < / > Lint source files
< g > init < / > Initialize a new project
< g > test < / > Run tests
< p ( 245 ) > deno test | deno test test . ts < / >
< g > publish < / > Publish the current working directory ' s package or workspace
< g > upgrade < / > Upgrade deno executable to given version
2024-08-30 20:22:20 -04:00
< p ( 245 ) > deno upgrade | deno upgrade 1.4 5.0 | deno upgrade canary < / >
2024-08-12 11:55:33 -04:00
{ after - help }
< y > Docs :< / > https ://docs.deno.com
< y > Standard Library :< / > https ://jsr.io/@std
< y > Bugs :< / > https ://github.com/denoland/deno/issues
< y > Discord :< / > https ://discord.gg/deno
" );
2019-05-23 14:57:44 -04:00
2019-11-26 11:06:32 -05:00
/// Main entry point for parsing deno's command line flags.
2024-03-22 17:03:56 -04:00
pub fn flags_from_vec ( args : Vec < OsString > ) -> clap ::error ::Result < Flags > {
2023-03-26 00:06:18 -04:00
let mut app = clap_root ( ) ;
let mut matches = app . try_get_matches_from_mut ( & args ) ? ;
2019-11-26 11:06:32 -05:00
2020-02-26 05:52:15 -05:00
let mut flags = Flags ::default ( ) ;
2019-11-26 11:06:32 -05:00
2023-03-26 00:06:18 -04:00
if matches . get_flag ( " quiet " ) {
2020-03-10 08:26:17 -04:00
flags . log_level = Some ( Level ::Error ) ;
2023-03-26 00:06:18 -04:00
} else if let Some ( log_level ) = matches . get_one ::< String > ( " log-level " ) {
flags . log_level = match log_level . as_str ( ) {
2023-09-09 14:03:19 -04:00
" trace " = > Some ( Level ::Trace ) ,
2023-03-26 00:06:18 -04:00
" debug " = > Some ( Level ::Debug ) ,
" info " = > Some ( Level ::Info ) ,
_ = > unreachable! ( ) ,
} ;
2020-03-10 08:26:17 -04:00
}
2019-11-26 11:06:32 -05:00
2024-08-18 18:39:53 -04:00
if let Some ( help_expansion ) = matches . get_one ::< String > ( " help " ) . cloned ( ) {
let mut subcommand = if let Some ( ( sub , _ ) ) = matches . remove_subcommand ( ) {
app . find_subcommand ( sub ) . unwrap ( ) . clone ( )
} else {
app
} ;
if help_expansion = = " unstable "
& & subcommand
. get_arguments ( )
. any ( | arg | arg . get_id ( ) . as_str ( ) = = " unstable " )
{
subcommand = subcommand
. mut_arg ( " unstable " , | arg | {
let new_help = arg
. get_help ( )
. unwrap ( )
. to_string ( )
. split_once ( " \n " )
. unwrap ( )
. 0
. to_string ( ) ;
arg . help_heading ( UNSTABLE_HEADING ) . help ( new_help )
} )
. mut_args ( | arg | {
// long_help here is being used as a metadata, see unstable args definition
if arg . get_help_heading ( ) = = Some ( UNSTABLE_HEADING )
& & arg . get_long_help ( ) . is_some ( )
{
arg . hide ( false )
} else {
arg
}
} ) ;
}
help_parse ( & mut flags , subcommand ) ;
return Ok ( flags ) ;
} else if matches . contains_id ( " help " ) {
let subcommand = if let Some ( ( sub , _ ) ) = matches . remove_subcommand ( ) {
app . find_subcommand ( sub ) . unwrap ( ) . clone ( )
} else {
app
} ;
2024-08-21 09:54:59 -04:00
help_parse ( & mut flags , subcommand ) ;
return Ok ( flags ) ;
} else if let Some ( help_subcommand_matches ) =
matches . subcommand_matches ( " help " )
{
app . build ( ) ;
let subcommand =
if let Some ( sub ) = help_subcommand_matches . subcommand_name ( ) {
app . find_subcommand ( sub ) . unwrap ( ) . clone ( )
} else {
app
} ;
2024-08-18 18:39:53 -04:00
help_parse ( & mut flags , subcommand ) ;
return Ok ( flags ) ;
}
2023-03-26 00:06:18 -04:00
if let Some ( ( subcommand , mut m ) ) = matches . remove_subcommand ( ) {
match subcommand . as_str ( ) {
2024-02-29 14:12:04 -05:00
" add " = > add_parse ( & mut flags , & mut m ) ,
2024-08-12 16:17:25 -04:00
" remove " = > remove_parse ( & mut flags , & mut m ) ,
2023-03-26 00:06:18 -04:00
" bench " = > bench_parse ( & mut flags , & mut m ) ,
" bundle " = > bundle_parse ( & mut flags , & mut m ) ,
" cache " = > cache_parse ( & mut flags , & mut m ) ,
" check " = > check_parse ( & mut flags , & mut m ) ,
2024-08-08 09:22:18 -04:00
" clean " = > clean_parse ( & mut flags , & mut m ) ,
2023-03-26 00:06:18 -04:00
" compile " = > compile_parse ( & mut flags , & mut m ) ,
" completions " = > completions_parse ( & mut flags , & mut m , app ) ,
" coverage " = > coverage_parse ( & mut flags , & mut m ) ,
" doc " = > doc_parse ( & mut flags , & mut m ) ,
" eval " = > eval_parse ( & mut flags , & mut m ) ,
" fmt " = > fmt_parse ( & mut flags , & mut m ) ,
" init " = > init_parse ( & mut flags , & mut m ) ,
" info " = > info_parse ( & mut flags , & mut m ) ,
" install " = > install_parse ( & mut flags , & mut m ) ,
2024-08-12 11:55:33 -04:00
" json_reference " = > json_reference_parse ( & mut flags , & mut m , app ) ,
2023-09-15 20:42:09 -04:00
" jupyter " = > jupyter_parse ( & mut flags , & mut m ) ,
2023-03-26 00:06:18 -04:00
" lint " = > lint_parse ( & mut flags , & mut m ) ,
" lsp " = > lsp_parse ( & mut flags , & mut m ) ,
" repl " = > repl_parse ( & mut flags , & mut m ) ,
2024-08-12 11:55:33 -04:00
" run " = > run_parse ( & mut flags , & mut m , app , false ) ? ,
2024-04-24 15:45:49 -04:00
" serve " = > serve_parse ( & mut flags , & mut m , app ) ? ,
2023-03-26 00:06:18 -04:00
" task " = > task_parse ( & mut flags , & mut m ) ,
" test " = > test_parse ( & mut flags , & mut m ) ,
" types " = > types_parse ( & mut flags , & mut m ) ,
" uninstall " = > uninstall_parse ( & mut flags , & mut m ) ,
" upgrade " = > upgrade_parse ( & mut flags , & mut m ) ,
" vendor " = > vendor_parse ( & mut flags , & mut m ) ,
2024-01-08 15:07:36 -05:00
" publish " = > publish_parse ( & mut flags , & mut m ) ,
2023-03-26 00:06:18 -04:00
_ = > unreachable! ( ) ,
}
} else {
2024-08-08 10:22:28 -04:00
let has_non_globals = app
. get_arguments ( )
. filter ( | arg | ! arg . is_global_set ( ) )
. any ( | arg | {
matches
. value_source ( arg . get_id ( ) . as_str ( ) )
. is_some_and ( | value | value ! = clap ::parser ::ValueSource ::DefaultValue )
} ) ;
if has_non_globals | | matches . contains_id ( " script_arg " ) {
2024-08-12 11:55:33 -04:00
run_parse ( & mut flags , & mut matches , app , true ) ? ;
2024-08-08 10:22:28 -04:00
} else {
handle_repl_flags (
& mut flags ,
ReplFlags {
eval_files : None ,
eval : None ,
is_default_command : true ,
} ,
)
}
2019-11-26 11:06:32 -05:00
}
Ok ( flags )
}
2024-08-18 18:39:53 -04:00
macro_rules ! heading {
( $( $name :ident = $title :expr ) , + ; $total :literal ) = > {
$( const $name : & str = $title ; ) +
const HEADING_ORDER : [ & str ; $total ] = [ $( $name ) , + ] ;
} ;
}
heading! {
// subcommand flags headings
DOC_HEADING = " Documentation options " ,
FMT_HEADING = " Formatting options " ,
COMPILE_HEADING = " Compile options " ,
LINT_HEADING = " Linting options " ,
TEST_HEADING = " Testing options " ,
UPGRADE_HEADING = " Upgrade options " ,
PUBLISH_HEADING = " Publishing options " ,
// categorized flags headings
TYPE_CHECKING_HEADING = " Type checking options " ,
FILE_WATCHING_HEADING = " File watching options " ,
DEBUGGING_HEADING = " Debugging options " ,
DEPENDENCY_MANAGEMENT_HEADING = " Dependency management options " ,
UNSTABLE_HEADING = " Unstable options " ;
12
}
fn help_parse ( flags : & mut Flags , mut subcommand : Command ) {
let mut args = subcommand
. get_arguments ( )
. map ( | arg | {
(
arg . get_id ( ) . as_str ( ) . to_string ( ) ,
arg . get_help_heading ( ) . map ( | h | h . to_string ( ) ) ,
)
} )
. collect ::< Vec < _ > > ( ) ;
args . sort_by ( | a , b | {
a . 1
. as_ref ( )
. map ( | heading | HEADING_ORDER . iter ( ) . position ( | h | h = = heading ) )
. cmp (
& b . 1
. as_ref ( )
. map ( | heading | HEADING_ORDER . iter ( ) . position ( | h | h = = heading ) ) ,
)
. then ( a . 0. cmp ( & b . 0 ) )
} ) ;
for ( mut i , ( arg , heading ) ) in args . into_iter ( ) . enumerate ( ) {
if let Some ( heading ) = heading {
let heading_i = HEADING_ORDER . iter ( ) . position ( | h | h = = & heading ) . unwrap ( ) ;
2024-08-21 09:54:59 -04:00
i + = heading_i * 100 ;
2024-08-18 18:39:53 -04:00
}
subcommand = subcommand . mut_arg ( arg , | arg | arg . display_order ( i ) ) ;
}
flags . subcommand = DenoSubcommand ::Help ( HelpFlags {
help : subcommand . render_help ( ) ,
} ) ;
}
2024-08-12 11:55:33 -04:00
// copied from clap, https://github.com/clap-rs/clap/blob/4e1a565b8adb4f2ad74a9631565574767fdc37ae/clap_builder/src/parser/features/suggestions.rs#L11-L26
pub fn did_you_mean < T , I > ( v : & str , possible_values : I ) -> Vec < String >
where
T : AsRef < str > ,
I : IntoIterator < Item = T > ,
{
let mut candidates : Vec < ( f64 , String ) > = possible_values
. into_iter ( )
// GH #4660: using `jaro` because `jaro_winkler` implementation in `strsim-rs` is wrong
// causing strings with common prefix >=10 to be considered perfectly similar
. map ( | pv | ( strsim ::jaro ( v , pv . as_ref ( ) ) , pv . as_ref ( ) . to_owned ( ) ) )
// Confidence of 0.7 so that bar -> baz is suggested
. filter ( | ( confidence , _ ) | * confidence > 0.7 )
. collect ( ) ;
candidates
. sort_by ( | a , b | a . 0. partial_cmp ( & b . 0 ) . unwrap_or ( std ::cmp ::Ordering ::Equal ) ) ;
candidates . into_iter ( ) . map ( | ( _ , pv ) | pv ) . collect ( )
}
2022-01-14 11:38:17 -05:00
fn handle_repl_flags ( flags : & mut Flags , repl_flags : ReplFlags ) {
2022-12-07 14:21:18 -05:00
// If user runs just `deno` binary we enter REPL and allow all permissions.
if repl_flags . is_default_command {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_net = Some ( vec! [ ] ) ;
flags . permissions . allow_env = Some ( vec! [ ] ) ;
flags . permissions . allow_run = Some ( vec! [ ] ) ;
flags . permissions . allow_read = Some ( vec! [ ] ) ;
flags . permissions . allow_sys = Some ( vec! [ ] ) ;
flags . permissions . allow_write = Some ( vec! [ ] ) ;
flags . permissions . allow_ffi = Some ( vec! [ ] ) ;
2022-12-07 14:21:18 -05:00
}
2022-01-14 11:38:17 -05:00
flags . subcommand = DenoSubcommand ::Repl ( repl_flags ) ;
}
2024-08-12 11:55:33 -04:00
pub fn clap_root ( ) -> Command {
2023-03-27 12:28:41 -04:00
let long_version = format! (
2024-08-16 16:42:19 -04:00
" {} ({}, {}, {}) \n v8 {} \n typescript {} " ,
2024-08-15 17:47:16 -04:00
crate ::version ::DENO_VERSION_INFO . deno ,
2024-08-16 16:42:19 -04:00
crate ::version ::DENO_VERSION_INFO . release_channel . name ( ) ,
env! ( " PROFILE " ) ,
2023-03-27 12:28:41 -04:00
env! ( " TARGET " ) ,
2024-08-19 10:51:16 -04:00
deno_core ::v8 ::VERSION_STRING ,
2024-08-15 17:47:16 -04:00
crate ::version ::DENO_VERSION_INFO . typescript
2023-03-27 12:28:41 -04:00
) ;
2024-08-18 18:39:53 -04:00
run_args ( Command ::new ( " deno " ) , true )
. args ( unstable_args ( UnstableArgsConfig ::ResolutionAndRuntime ) )
2024-08-12 11:55:33 -04:00
. next_line_help ( false )
2019-11-26 11:06:32 -05:00
. bin_name ( " deno " )
2024-01-23 13:56:50 -05:00
. styles (
clap ::builder ::Styles ::styled ( )
. header ( AnsiColor ::Yellow . on_default ( ) )
. usage ( AnsiColor ::White . on_default ( ) )
. literal ( AnsiColor ::Green . on_default ( ) )
2024-08-18 18:39:53 -04:00
. placeholder ( AnsiColor ::Green . on_default ( ) ) ,
2024-01-23 13:56:50 -05:00
)
. color ( ColorChoice ::Auto )
2024-08-12 11:55:33 -04:00
. term_width ( 800 )
2024-08-15 17:47:16 -04:00
. version ( crate ::version ::DENO_VERSION_INFO . deno )
2023-03-27 12:28:41 -04:00
. long_version ( long_version )
2024-05-22 20:20:20 -04:00
. disable_version_flag ( true )
2024-08-12 11:55:33 -04:00
. disable_help_flag ( true )
. disable_help_subcommand ( true )
2024-08-18 18:39:53 -04:00
. arg (
Arg ::new ( " help " )
. short ( 'h' )
. long ( " help " )
. hide ( true )
. action ( ArgAction ::Append )
. num_args ( 0 ..= 1 )
. require_equals ( true )
. value_parser ( [ " unstable " ] )
. global ( true ) ,
)
2024-05-22 20:20:20 -04:00
. arg (
Arg ::new ( " version " )
. short ( 'V' )
. short_alias ( 'v' )
. long ( " version " )
. action ( ArgAction ::Version )
2024-08-18 18:39:53 -04:00
. help ( " Print version " ) ,
2020-09-20 07:45:00 -04:00
)
2019-04-06 18:13:06 -04:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " log-level " )
. short ( 'L' )
2019-06-22 12:02:51 -04:00
. long ( " log-level " )
. help ( " Set log level " )
2022-04-11 01:01:02 -04:00
. hide ( true )
2023-09-09 14:03:19 -04:00
. value_parser ( [ " trace " , " debug " , " info " ] )
2019-05-03 17:15:16 -04:00
. global ( true ) ,
2019-07-31 11:02:20 -04:00
)
2020-03-10 08:26:17 -04:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " quiet " )
. short ( 'q' )
2020-03-10 08:26:17 -04:00
. long ( " quiet " )
. help ( " Suppress diagnostic output " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2020-03-10 08:26:17 -04:00
. global ( true ) ,
)
2019-11-26 11:06:32 -05:00
. subcommand ( run_subcommand ( ) )
2024-04-24 15:45:49 -04:00
. subcommand ( serve_subcommand ( ) )
2023-06-12 07:54:04 -04:00
. defer ( | cmd | {
2024-08-12 11:55:33 -04:00
let cmd = cmd
2024-02-29 14:12:04 -05:00
. subcommand ( add_subcommand ( ) )
2024-08-12 16:17:25 -04:00
. subcommand ( remove_subcommand ( ) )
2023-06-12 07:54:04 -04:00
. subcommand ( bench_subcommand ( ) )
. subcommand ( bundle_subcommand ( ) )
. subcommand ( cache_subcommand ( ) )
. subcommand ( check_subcommand ( ) )
2024-08-08 09:22:18 -04:00
. subcommand ( clean_subcommand ( ) )
2023-06-12 07:54:04 -04:00
. subcommand ( compile_subcommand ( ) )
. subcommand ( completions_subcommand ( ) )
. subcommand ( coverage_subcommand ( ) )
. subcommand ( doc_subcommand ( ) )
. subcommand ( eval_subcommand ( ) )
. subcommand ( fmt_subcommand ( ) )
. subcommand ( init_subcommand ( ) )
. subcommand ( info_subcommand ( ) )
2024-08-30 17:58:24 -04:00
. subcommand ( future_install_subcommand ( ) )
2024-08-12 11:55:33 -04:00
. subcommand ( json_reference_subcommand ( ) )
2023-09-15 20:42:09 -04:00
. subcommand ( jupyter_subcommand ( ) )
2023-06-12 07:54:04 -04:00
. subcommand ( uninstall_subcommand ( ) )
. subcommand ( lsp_subcommand ( ) )
. subcommand ( lint_subcommand ( ) )
2023-11-23 18:38:07 -05:00
. subcommand ( publish_subcommand ( ) )
2023-06-12 07:54:04 -04:00
. subcommand ( repl_subcommand ( ) )
. subcommand ( task_subcommand ( ) )
. subcommand ( test_subcommand ( ) )
. subcommand ( types_subcommand ( ) )
. subcommand ( upgrade_subcommand ( ) )
2024-08-12 11:55:33 -04:00
. subcommand ( vendor_subcommand ( ) ) ;
let help = help_subcommand ( & cmd ) ;
cmd . subcommand ( help )
2023-06-12 07:54:04 -04:00
} )
2024-08-12 11:55:33 -04:00
. help_template ( DENO_HELP )
2019-11-26 11:06:32 -05:00
. after_help ( ENV_VARIABLES_HELP )
2024-08-12 11:55:33 -04:00
. next_line_help ( false )
}
2024-08-18 18:39:53 -04:00
#[ inline(always) ]
fn command (
name : & 'static str ,
about : impl clap ::builder ::IntoResettable < clap ::builder ::StyledStr > ,
unstable_args_config : UnstableArgsConfig ,
) -> Command {
Command ::new ( name )
. about ( about )
. args ( unstable_args ( unstable_args_config ) )
}
2024-08-12 11:55:33 -04:00
fn help_subcommand ( app : & Command ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " help " , None , UnstableArgsConfig ::None )
2024-08-21 09:54:59 -04:00
. disable_version_flag ( true )
2024-08-12 11:55:33 -04:00
. disable_help_subcommand ( true )
. subcommands ( app . get_subcommands ( ) . map ( | command | {
Command ::new ( command . get_name ( ) . to_owned ( ) )
. disable_help_flag ( true )
. disable_version_flag ( true )
} ) )
2019-11-26 11:06:32 -05:00
}
2019-11-13 10:35:56 -05:00
2024-02-29 14:12:04 -05:00
fn add_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" add " ,
" Add dependencies to the configuration file.
2024-02-29 14:12:04 -05:00
deno add @ std / path
You can add multiple dependencies at once :
deno add @ std / path @ std / assert
" ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd . arg (
Arg ::new ( " packages " )
. help ( " List of packages to add " )
. required_unless_present ( " help " )
. num_args ( 1 .. )
. action ( ArgAction ::Append ) ,
2024-02-29 14:12:04 -05:00
)
2024-08-18 18:39:53 -04:00
} )
2024-02-29 14:12:04 -05:00
}
2024-08-12 16:17:25 -04:00
fn remove_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" remove " ,
2024-08-21 09:54:59 -04:00
cstr! (
" Remove dependencies from the configuration file.
2024-08-12 16:17:25 -04:00
deno remove @ std / path
You can remove multiple dependencies at once :
2024-08-18 18:39:53 -04:00
< p ( 245 ) > deno remove @ std / path @ std / assert < / >
2024-08-21 09:54:59 -04:00
"
) ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd . arg (
Arg ::new ( " packages " )
. help ( " List of packages to remove " )
. required_unless_present ( " help " )
. num_args ( 1 .. )
. action ( ArgAction ::Append ) ,
2024-08-12 16:17:25 -04:00
)
2024-08-18 18:39:53 -04:00
} )
2024-08-12 16:17:25 -04:00
}
2023-03-26 00:06:18 -04:00
fn bench_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" bench " ,
" Run benchmarks using Deno's built-in bench tool.
2022-03-11 17:07:02 -05:00
2023-03-27 12:28:41 -04:00
Evaluate the given modules , run all benches declared with ' Deno . bench ( ) '
2022-04-11 01:01:02 -04:00
and report results to standard output :
2022-03-11 17:07:02 -05:00
deno bench src / fetch_bench . ts src / signal_bench . ts
2023-03-27 12:28:41 -04:00
Directory arguments are expanded to all contained files matching the
2022-08-15 15:16:23 -04:00
glob { * _ , * . , } bench . { js , mjs , ts , mts , jsx , tsx } :
2022-03-11 17:07:02 -05:00
deno bench src / " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionAndRuntime ,
)
. defer ( | cmd | {
runtime_args ( cmd , true , false )
. arg ( check_arg ( true ) )
. arg (
Arg ::new ( " json " )
. long ( " json " )
. action ( ArgAction ::SetTrue )
. help ( " UNSTABLE: Output benchmark result in JSON format " ) ,
)
. arg (
Arg ::new ( " ignore " )
. long ( " ignore " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. help ( " Ignore files " ) ,
)
. arg (
Arg ::new ( " filter " )
. long ( " filter " )
. allow_hyphen_values ( true )
2024-08-21 09:54:59 -04:00
. help (
" Run benchmarks with this string or regexp pattern in the bench name " ,
) ,
2024-08-18 18:39:53 -04:00
)
. arg (
Arg ::new ( " files " )
. help ( " List of file names to run " )
. num_args ( .. )
. action ( ArgAction ::Append ) ,
)
. arg (
Arg ::new ( " no-run " )
. long ( " no-run " )
. help ( " Cache bench modules, but don't run benchmarks " )
. action ( ArgAction ::SetTrue ) ,
)
. arg ( watch_arg ( false ) )
. arg ( watch_exclude_arg ( ) )
. arg ( no_clear_screen_arg ( ) )
. arg ( script_arg ( ) . last ( true ) )
. arg ( env_file_arg ( ) )
} )
2022-03-11 17:07:02 -05:00
}
2023-03-26 00:06:18 -04:00
fn bundle_subcommand ( ) -> Command {
2024-09-02 11:27:37 -04:00
command ( " bundle " , " ⚠️ `deno bundle` was removed in Deno 2.
2021-04-16 09:28:41 -04:00
2024-09-02 11:27:37 -04:00
See the Deno 1. x to 2. x Migration Guide for migration instructions : https ://docs.deno.com/runtime/manual/advanced/migrate_deprecations", UnstableArgsConfig::ResolutionOnly)
2024-08-18 18:39:53 -04:00
. hide ( true )
2019-11-26 11:06:32 -05:00
}
2019-06-11 14:38:19 -04:00
2023-03-26 00:06:18 -04:00
fn cache_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" cache " ,
" Cache and compile remote dependencies recursively.
2021-01-19 12:39:35 -05:00
2023-03-27 12:28:41 -04:00
Download and compile a module with all of its static dependencies and save
2022-04-11 01:01:02 -04:00
them in the local cache , without running any code :
2024-04-10 17:26:35 -04:00
deno cache jsr :@ std / http / file - server
2021-04-16 09:28:41 -04:00
2023-03-27 12:28:41 -04:00
Future runs of this module will trigger no downloads or compilation unless
2021-04-16 09:28:41 -04:00
- - reload is specified . " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionOnly ,
)
. defer ( | cmd | {
compile_args ( cmd )
. arg ( check_arg ( false ) )
. arg (
Arg ::new ( " file " )
. num_args ( 1 .. )
. required_unless_present ( " help " )
. value_hint ( ValueHint ::FilePath ) ,
)
. arg ( frozen_lockfile_arg ( ) )
. arg ( allow_scripts_arg ( ) )
} )
2019-11-26 11:06:32 -05:00
}
2019-05-01 19:15:37 -04:00
2024-08-08 09:22:18 -04:00
fn clean_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" clean " ,
" Remove the cache directory ($DENO_DIR) " ,
UnstableArgsConfig ::None ,
)
2024-08-08 09:22:18 -04:00
}
2023-03-26 00:06:18 -04:00
fn check_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " check " ,
2024-08-12 11:55:33 -04:00
" Download and type-check without execution.
2023-06-27 20:57:20 -04:00
2024-04-10 17:26:35 -04:00
deno check jsr :@ std / http / file - server
2023-06-27 20:57:20 -04:00
Unless - - reload is specified , this command will not re - download already cached dependencies . " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionAndRuntime
2024-08-12 11:55:33 -04:00
)
2024-08-18 18:39:53 -04:00
. defer ( | cmd | {
compile_args_without_check_args ( cmd )
. arg (
Arg ::new ( " all " )
. long ( " all " )
. help ( " Type-check all code, including remote modules and npm packages " )
. action ( ArgAction ::SetTrue )
. conflicts_with ( " no-remote " )
)
. arg (
// past alias for --all
Arg ::new ( " remote " )
. long ( " remote " )
2024-08-21 09:54:59 -04:00
. help ( " Type-check all modules, including remote ones " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. conflicts_with ( " no-remote " )
. hide ( true )
)
. arg (
Arg ::new ( " file " )
. num_args ( 1 .. )
. required_unless_present ( " help " )
. value_hint ( ValueHint ::FilePath ) ,
)
}
2023-06-27 20:57:20 -04:00
)
2022-04-10 19:12:51 -04:00
}
2023-03-26 00:06:18 -04:00
fn compile_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" compile " ,
" Compiles the given script into a self contained executable.
2023-06-27 20:57:20 -04:00
2024-04-10 17:26:35 -04:00
deno compile - A jsr :@ std / http / file - server
deno compile - - output file_server jsr :@ std / http / file - server
2023-06-27 20:57:20 -04:00
Any flags passed which affect runtime behavior , such as ' - - unstable ' ,
' - - allow - * ' , ' - - v8 - flags ' , etc . are encoded into the output executable and
used at runtime as if they were passed to a similar ' deno run ' command .
The executable name is inferred by default : Attempt to take the file stem of
the URL path . The above example would become ' file_server ' . If the file stem
is something generic like ' main ' , ' mod ' , ' index ' or ' cli ' , and the path has no
parent , take the file name of the parent path . Otherwise settle with the
generic name . If the resulting name has an ' @ .. . ' suffix , strip it .
Cross - compiling to different target architectures is supported using the
` - - target ` flag . On the first invocation with deno will download proper
binary and cache it in $DENO_DIR . The aarch64 - apple - darwin target is not
supported in canary .
" ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionAndRuntime ,
)
. defer ( | cmd | {
runtime_args ( cmd , true , false )
. arg ( check_arg ( true ) )
. arg (
Arg ::new ( " include " )
. long ( " include " )
. help (
2024-08-21 09:54:59 -04:00
cstr! ( " Includes an additional module in the compiled executable's module graph.
< p ( 245 ) > Use this flag if a dynamically imported module or a web worker main module
fails to load in the executable . This flag can be passed multiple times ,
to include multiple additional modules . < / > " ,
) )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::Append )
. value_hint ( ValueHint ::FilePath )
. help_heading ( COMPILE_HEADING ) ,
)
. arg (
Arg ::new ( " output " )
. long ( " output " )
. short ( 'o' )
. value_parser ( value_parser! ( String ) )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Output file <p(245)>(defaults to $PWD/<<inferred-name>>)</> " ) )
2024-08-18 18:39:53 -04:00
. value_hint ( ValueHint ::FilePath )
. help_heading ( COMPILE_HEADING ) ,
)
. arg (
Arg ::new ( " target " )
. long ( " target " )
. help ( " Target OS architecture " )
. value_parser ( [
" x86_64-unknown-linux-gnu " ,
" aarch64-unknown-linux-gnu " ,
" x86_64-pc-windows-msvc " ,
" x86_64-apple-darwin " ,
" aarch64-apple-darwin " ,
] )
. help_heading ( COMPILE_HEADING ) ,
)
. arg (
Arg ::new ( " no-terminal " )
. long ( " no-terminal " )
. help ( " Hide terminal on Windows " )
. action ( ArgAction ::SetTrue )
. help_heading ( COMPILE_HEADING ) ,
)
. arg (
Arg ::new ( " icon " )
. long ( " icon " )
. help ( " Set the icon of the executable on Windows (.ico) " )
. value_parser ( value_parser! ( String ) )
. help_heading ( COMPILE_HEADING ) ,
)
. arg ( executable_ext_arg ( ) )
. arg ( env_file_arg ( ) )
. arg (
script_arg ( )
. required_unless_present ( " help " )
. trailing_var_arg ( true ) ,
)
} )
2019-11-26 11:06:32 -05:00
}
2019-05-01 19:15:37 -04:00
2023-03-26 00:06:18 -04:00
fn completions_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" completions " ,
" Output shell completion script to standard output.
2021-04-18 09:12:55 -04:00
2021-04-16 09:28:41 -04:00
deno completions bash > / usr / local / etc / bash_completion . d / deno . bash
source / usr / local / etc / bash_completion . d / deno . bash " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd . disable_help_subcommand ( true ) . arg (
Arg ::new ( " shell " )
. value_parser ( [ " bash " , " fish " , " powershell " , " zsh " , " fig " ] )
. required_unless_present ( " help " ) ,
2023-06-27 20:57:20 -04:00
)
2024-08-18 18:39:53 -04:00
} )
2020-11-30 14:35:12 -05:00
}
2023-03-26 00:06:18 -04:00
fn coverage_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" coverage " ,
" Print coverage reports from coverage profiles.
2020-02-17 11:59:51 -05:00
2021-04-16 09:28:41 -04:00
Collect a coverage profile with deno test :
deno test - - coverage = cov_profile
2020-02-04 14:24:33 -05:00
2021-04-16 09:28:41 -04:00
Print a report to stdout :
deno coverage cov_profile
2020-02-04 14:24:33 -05:00
2021-04-16 09:28:41 -04:00
Include urls that start with the file schema :
deno coverage - - include = \ " ^file: \" cov_profile
2020-11-22 15:45:44 -05:00
2021-04-16 09:28:41 -04:00
Exclude urls ending with test . ts and test . js :
deno coverage - - exclude = \ " test \\ .(ts|js) \" cov_profile
2019-05-23 14:57:44 -04:00
2023-03-27 12:28:41 -04:00
Include urls that start with the file schema and exclude files ending with
test . ts and test . js , for an url to match it must match the include pattern and
2022-04-11 01:01:02 -04:00
not match the exclude pattern :
2021-04-16 09:28:41 -04:00
deno coverage - - include = \ " ^file: \" --exclude= \" test \\ .(ts|js) \" cov_profile
2020-02-04 14:24:33 -05:00
2021-04-16 09:28:41 -04:00
Write a report using the lcov format :
2024-08-18 18:39:53 -04:00
deno coverage - - lcov - - output = cov . lcov cov_profile /
Generate html reports from lcov :
genhtml - o html_cov cov . lcov
" ,
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd
. arg (
Arg ::new ( " ignore " )
. long ( " ignore " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. help ( " Ignore coverage files " )
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg (
Arg ::new ( " include " )
. long ( " include " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. value_name ( " regex " )
. require_equals ( true )
. default_value ( r "^file:" )
. help ( " Include source files in the report " ) ,
)
. arg (
Arg ::new ( " exclude " )
. long ( " exclude " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. value_name ( " regex " )
. require_equals ( true )
. default_value ( r "test\.(js|mjs|ts|jsx|tsx)$" )
. help ( " Exclude source files from the report " ) ,
)
. arg (
Arg ::new ( " lcov " )
. long ( " lcov " )
. help ( " Output coverage report in lcov format " )
. action ( ArgAction ::SetTrue ) ,
)
. arg (
Arg ::new ( " output " )
. requires ( " lcov " )
. long ( " output " )
. value_parser ( value_parser! ( String ) )
. help (
2024-08-21 09:54:59 -04:00
cstr! ( " Exports the coverage report in lcov format to the given file.
< p ( 245 ) > If no - - output arg is specified then the report is written to stdout . < / > " ,
) )
2024-08-18 18:39:53 -04:00
. require_equals ( true )
. value_hint ( ValueHint ::FilePath ) ,
)
. arg (
Arg ::new ( " html " )
. long ( " html " )
. help ( " Output coverage report in HTML format in the given directory " )
. action ( ArgAction ::SetTrue ) ,
)
. arg (
Arg ::new ( " detailed " )
. long ( " detailed " )
2024-08-21 09:54:59 -04:00
. help ( " Output coverage report in detailed format in the terminal " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue ) ,
)
. arg (
Arg ::new ( " files " )
. num_args ( 0 .. )
. action ( ArgAction ::Append )
. value_hint ( ValueHint ::AnyPath ) ,
)
} )
2019-11-26 11:06:32 -05:00
}
2019-08-11 20:43:01 -04:00
2023-03-26 00:06:18 -04:00
fn doc_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " doc " ,
2023-06-27 20:57:20 -04:00
" Show documentation for a module.
2019-05-01 19:15:37 -04:00
2021-04-16 09:28:41 -04:00
Output documentation to standard output :
deno doc . / path / to / module . ts
2019-05-01 19:15:37 -04:00
2023-11-01 11:25:05 -04:00
Output documentation in HTML format :
deno doc - - html - - name = \ " My library \" ./path/to/module.ts
deno doc - - html - - name = \ " My library \" ./main.ts ./dev.ts
deno doc - - html - - name = \ " My library \" --output=./documentation/ ./path/to/module.ts
2021-04-16 09:28:41 -04:00
Output private documentation to standard output :
deno doc - - private . / path / to / module . ts
2019-05-01 19:15:37 -04:00
2021-04-16 09:28:41 -04:00
Output documentation in JSON format :
deno doc - - json . / path / to / module . ts
2021-02-24 09:27:51 -05:00
2023-10-31 18:19:42 -04:00
Lint a module for documentation diagnostics :
deno doc - - lint . / path / to / module . ts
2021-04-16 09:28:41 -04:00
Target a specific symbol :
deno doc . / path / to / module . ts MyClass . someField
2019-05-06 10:48:19 -04:00
2021-04-16 09:28:41 -04:00
Show documentation for runtime built - ins :
deno doc
2024-04-04 18:03:29 -04:00
deno doc - - filter Deno . Listener " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionOnly
2023-06-27 20:57:20 -04:00
)
. defer ( | cmd | {
cmd
. arg ( import_map_arg ( ) )
. arg ( reload_arg ( ) )
. arg ( lock_arg ( ) )
. arg ( no_lock_arg ( ) )
. arg ( no_npm_arg ( ) )
. arg ( no_remote_arg ( ) )
. arg (
Arg ::new ( " json " )
. long ( " json " )
. help ( " Output documentation in JSON format " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( DOC_HEADING ) ,
2023-06-27 20:57:20 -04:00
)
2023-11-01 11:25:05 -04:00
. arg (
Arg ::new ( " html " )
. long ( " html " )
. help ( " Output documentation in HTML format " )
. action ( ArgAction ::SetTrue )
2024-08-18 18:39:53 -04:00
. display_order ( 1000 )
. conflicts_with ( " json " ) . help_heading ( DOC_HEADING )
2023-11-01 11:25:05 -04:00
)
. arg (
Arg ::new ( " name " )
. long ( " name " )
2024-08-21 09:54:59 -04:00
. help ( " The name that will be used in the docs (ie for breadcrumbs) " )
2023-11-01 11:25:05 -04:00
. action ( ArgAction ::Set )
2024-08-18 18:39:53 -04:00
. require_equals ( true ) . help_heading ( DOC_HEADING )
2023-11-01 11:25:05 -04:00
)
2024-06-28 08:03:51 -04:00
. arg (
Arg ::new ( " category-docs " )
. long ( " category-docs " )
. help ( " Path to a JSON file keyed by category and an optional value of a markdown doc " )
. requires ( " html " )
. action ( ArgAction ::Set )
2024-08-18 18:39:53 -04:00
. require_equals ( true ) . help_heading ( DOC_HEADING )
2024-06-28 08:03:51 -04:00
)
. arg (
Arg ::new ( " symbol-redirect-map " )
. long ( " symbol-redirect-map " )
. help ( " Path to a JSON file keyed by file, with an inner map of symbol to an external link " )
. requires ( " html " )
. action ( ArgAction ::Set )
2024-08-18 18:39:53 -04:00
. require_equals ( true ) . help_heading ( DOC_HEADING )
2024-06-28 08:03:51 -04:00
)
. arg (
Arg ::new ( " strip-trailing-html " )
. long ( " strip-trailing-html " )
2024-08-21 09:54:59 -04:00
. help ( " Remove trailing .html from various links. Will still generate files with a .html extension " )
2024-06-28 08:03:51 -04:00
. requires ( " html " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue ) . help_heading ( DOC_HEADING )
2024-06-28 08:03:51 -04:00
)
. arg (
Arg ::new ( " default-symbol-map " )
. long ( " default-symbol-map " )
2024-08-21 09:54:59 -04:00
. help ( " Uses the provided mapping of default name to wanted name for usage blocks " )
2024-06-28 08:03:51 -04:00
. requires ( " html " )
. action ( ArgAction ::Set )
2024-08-18 18:39:53 -04:00
. require_equals ( true ) . help_heading ( DOC_HEADING )
2024-06-28 08:03:51 -04:00
)
2023-11-01 11:25:05 -04:00
. arg (
Arg ::new ( " output " )
. long ( " output " )
. help ( " Directory for HTML documentation output " )
. action ( ArgAction ::Set )
. require_equals ( true )
. value_hint ( ValueHint ::DirPath )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( String ) ) . help_heading ( DOC_HEADING )
2023-11-01 11:25:05 -04:00
)
2023-06-27 20:57:20 -04:00
. arg (
Arg ::new ( " private " )
. long ( " private " )
. help ( " Output private documentation " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue ) . help_heading ( DOC_HEADING ) ,
2023-06-27 20:57:20 -04:00
)
2023-10-30 18:58:57 -04:00
. arg (
Arg ::new ( " filter " )
. long ( " filter " )
. help ( " Dot separated path to symbol " )
2023-10-31 18:19:42 -04:00
. conflicts_with ( " json " )
2023-11-01 11:25:05 -04:00
. conflicts_with ( " lint " )
2024-08-18 18:39:53 -04:00
. conflicts_with ( " html " ) . help_heading ( DOC_HEADING ) ,
2023-10-31 18:19:42 -04:00
)
. arg (
Arg ::new ( " lint " )
. long ( " lint " )
. help ( " Output documentation diagnostics. " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue ) . help_heading ( DOC_HEADING ) ,
2023-10-30 18:58:57 -04:00
)
2023-06-27 20:57:20 -04:00
// TODO(nayeemrmn): Make `--builtin` a proper option. Blocked by
// https://github.com/clap-rs/clap/issues/1794. Currently `--builtin` is
// just a possible value of `source_file` so leading hyphens must be
// enabled.
. allow_hyphen_values ( true )
. arg (
2023-10-30 18:58:57 -04:00
Arg ::new ( " source_file " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
2023-11-03 13:06:18 -04:00
. value_hint ( ValueHint ::FilePath )
. required_if_eq_any ( [ ( " html " , " true " ) , ( " lint " , " true " ) ] ) ,
2023-06-27 20:57:20 -04:00
)
} )
2020-09-18 13:09:11 -04:00
}
2023-03-26 00:06:18 -04:00
fn eval_subcommand ( ) -> Command {
2024-09-02 11:27:26 -04:00
command (
" eval " ,
" Evaluate JavaScript from the command line.
2021-04-18 09:12:55 -04:00
2021-04-16 09:28:41 -04:00
deno eval \ " console.log('hello world') \"
2019-11-26 11:06:32 -05:00
2021-04-16 09:28:41 -04:00
To evaluate as TypeScript :
deno eval - - ext = ts \ " const v: string = 'hello'; console.log(v) \"
2019-11-26 11:06:32 -05:00
2021-04-16 09:28:41 -04:00
This command has implicit access to all permissions ( - - allow - all ) . " ,
2024-09-02 11:27:26 -04:00
UnstableArgsConfig ::ResolutionAndRuntime ,
)
. defer ( | cmd | {
runtime_args ( cmd , false , true )
. arg ( check_arg ( false ) )
. arg ( executable_ext_arg ( ) )
. arg (
Arg ::new ( " print " )
. long ( " print " )
. short ( 'p' )
. help ( " print result to stdout " )
. action ( ArgAction ::SetTrue ) ,
)
. arg (
Arg ::new ( " code_arg " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. help ( " Code to evaluate " )
. value_name ( " CODE_ARG " )
. required_unless_present ( " help " ) ,
)
. arg ( env_file_arg ( ) )
} )
2019-11-26 11:06:32 -05:00
}
2023-03-26 00:06:18 -04:00
fn fmt_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" fmt " ,
" Auto-format JavaScript, TypeScript, Markdown, and JSON files.
2021-04-18 09:12:55 -04:00
2021-04-16 09:28:41 -04:00
deno fmt
deno fmt myfile1 . ts myfile2 . ts
deno fmt - - check
2020-02-09 05:19:05 -05:00
2020-03-10 19:23:08 -04:00
Format stdin and write to stdout :
2020-05-04 15:17:15 -04:00
cat file . ts | deno fmt -
Ignore formatting code by preceding it with an ignore comment :
// deno-fmt-ignore
Ignore formatting a file by adding an ignore comment at the top of the file :
// deno-fmt-ignore-file",
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd
. arg ( config_arg ( ) )
. arg ( no_config_arg ( ) )
. arg (
2024-08-21 09:54:59 -04:00
Arg ::new ( " check " )
2024-08-18 18:39:53 -04:00
. long ( " check " )
. help ( " Check if the source files are formatted " )
. num_args ( 0 )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " ext " )
. long ( " ext " )
. help ( " Set content type of the supplied file " )
// prefer using ts for formatting instead of js because ts works in more scenarios
. default_value ( " ts " )
. value_parser ( [
" ts " , " tsx " , " js " , " jsx " , " md " , " json " , " jsonc " , " css " , " scss " ,
" sass " , " less " , " html " , " svelte " , " vue " , " astro " , " yml " , " yaml " ,
" ipynb " ,
] )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " ignore " )
. long ( " ignore " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. help ( " Ignore formatting particular source files " )
. value_hint ( ValueHint ::AnyPath )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " files " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg ( watch_arg ( false ) )
. arg ( watch_exclude_arg ( ) )
. arg ( no_clear_screen_arg ( ) )
. arg (
Arg ::new ( " use-tabs " )
. long ( " use-tabs " )
. alias ( " options-use-tabs " )
. num_args ( 0 ..= 1 )
. value_parser ( value_parser! ( bool ) )
. default_missing_value ( " true " )
. require_equals ( true )
. help (
2024-08-21 09:54:59 -04:00
cstr! ( " Use tabs instead of spaces for indentation <p(245)>[default: false]</> " ) ,
2024-08-18 18:39:53 -04:00
)
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " line-width " )
. long ( " line-width " )
. alias ( " options-line-width " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Define maximum line width <p(245)>[default: 80]</> " ) )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( NonZeroU32 ) )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " indent-width " )
. long ( " indent-width " )
. alias ( " options-indent-width " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Define indentation width <p(245)>[default: 2]</> " ) )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( NonZeroU8 ) )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " single-quote " )
. long ( " single-quote " )
. alias ( " options-single-quote " )
. num_args ( 0 ..= 1 )
. value_parser ( value_parser! ( bool ) )
. default_missing_value ( " true " )
. require_equals ( true )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Use single quotes <p(245)>[default: false]</> " ) )
2024-08-18 18:39:53 -04:00
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " prose-wrap " )
. long ( " prose-wrap " )
. alias ( " options-prose-wrap " )
. value_parser ( [ " always " , " never " , " preserve " ] )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Define how prose should be wrapped <p(245)>[default: always]</> " ) )
2024-08-18 18:39:53 -04:00
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " no-semicolons " )
. long ( " no-semicolons " )
. alias ( " options-no-semicolons " )
. num_args ( 0 ..= 1 )
. value_parser ( value_parser! ( bool ) )
. default_missing_value ( " true " )
. require_equals ( true )
. help (
2024-08-21 09:54:59 -04:00
cstr! ( " Don't use semicolons except where necessary <p(245)>[default: false]</> " ) ,
2024-08-18 18:39:53 -04:00
)
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " unstable-css " )
. long ( " unstable-css " )
2024-08-21 09:54:59 -04:00
. help ( " Enable formatting CSS, SCSS, Sass and Less files " )
2024-08-18 18:39:53 -04:00
. value_parser ( FalseyValueParser ::new ( ) )
. action ( ArgAction ::SetTrue )
. help_heading ( FMT_HEADING ) ,
)
. arg (
Arg ::new ( " unstable-html " )
. long ( " unstable-html " )
2024-08-21 09:54:59 -04:00
. help ( " Enable formatting HTML files " )
2024-08-18 18:39:53 -04:00
. value_parser ( FalseyValueParser ::new ( ) )
2024-08-21 09:54:59 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( FMT_HEADING ) ,
2024-08-18 18:39:53 -04:00
)
. arg (
Arg ::new ( " unstable-component " )
. long ( " unstable-component " )
2024-08-21 09:54:59 -04:00
. help ( " Enable formatting Svelte, Vue, Astro and Angular files " )
2024-08-18 18:39:53 -04:00
. value_parser ( FalseyValueParser ::new ( ) )
2024-08-21 09:54:59 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( FMT_HEADING ) ,
2024-08-18 18:39:53 -04:00
)
. arg (
Arg ::new ( " unstable-yaml " )
. long ( " unstable-yaml " )
2024-08-21 09:54:59 -04:00
. help ( " Enable formatting YAML files " )
2024-08-18 18:39:53 -04:00
. value_parser ( FalseyValueParser ::new ( ) )
. action ( ArgAction ::SetTrue )
. help_heading ( FMT_HEADING ) ,
)
} )
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2023-03-26 00:06:18 -04:00
fn init_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " init " , " Initialize a new project " , UnstableArgsConfig ::None ) . defer (
| cmd | {
2024-07-09 21:13:34 -04:00
cmd
2024-08-18 18:39:53 -04:00
. arg ( Arg ::new ( " dir " ) . value_hint ( ValueHint ::DirPath ) )
2024-08-21 09:54:59 -04:00
. arg (
Arg ::new ( " lib " )
. long ( " lib " )
. help ( " Generate an example library project " )
. action ( ArgAction ::SetTrue ) ,
)
2024-08-08 12:54:39 -04:00
. arg (
Arg ::new ( " serve " )
. long ( " serve " )
2024-08-18 18:39:53 -04:00
. help ( " Generate an example project for `deno serve` " )
2024-08-08 12:54:39 -04:00
. conflicts_with ( " lib " )
. action ( ArgAction ::SetTrue ) ,
)
2024-08-18 18:39:53 -04:00
} ,
)
2022-08-19 19:37:05 -04:00
}
2023-03-26 00:06:18 -04:00
fn info_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " info " ,
2024-08-12 11:55:33 -04:00
" Information about a module or the cache directories.
2021-04-16 09:28:41 -04:00
Get information about a module :
2024-04-10 17:26:35 -04:00
deno info jsr :@ std / http / file - server
2021-04-16 09:28:41 -04:00
The following information is shown :
local : Local path of the file .
type : JavaScript , TypeScript , or JSON .
2021-09-13 07:50:04 -04:00
emit : Local path of compiled source code . ( TypeScript only . )
dependencies : Dependency tree of the source file .
2021-04-16 09:28:41 -04:00
Without any additional arguments , ' deno info ' shows :
DENO_DIR : Directory containing Deno - managed files .
Remote modules cache : Subdirectory containing downloaded remote modules .
TypeScript compiler cache : Subdirectory containing TS compiler output . " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionOnly
2024-08-12 11:55:33 -04:00
)
2023-06-27 20:57:20 -04:00
. defer ( | cmd | cmd
2024-08-18 18:39:53 -04:00
. arg ( Arg ::new ( " file " ) . value_hint ( ValueHint ::FilePath ) )
2023-06-12 07:54:04 -04:00
. arg ( reload_arg ( ) . requires ( " file " ) )
. arg ( ca_file_arg ( ) )
2024-08-18 18:39:53 -04:00
. arg ( unsafely_ignore_certificate_errors_arg ( ) )
2023-06-12 07:54:04 -04:00
. arg (
location_arg ( )
. conflicts_with ( " file " )
. help ( " Show files used for origin bound APIs like the Web Storage API when running a script with '--location=<HREF>' " )
)
. arg ( no_check_arg ( ) . hide ( true ) ) // TODO(lucacasonato): remove for 2.0
. arg ( no_config_arg ( ) )
. arg ( no_remote_arg ( ) )
. arg ( no_npm_arg ( ) )
. arg ( lock_arg ( ) )
2024-02-19 07:02:40 -05:00
. arg ( no_lock_arg ( ) )
2023-06-12 07:54:04 -04:00
. arg ( config_arg ( ) )
. arg ( import_map_arg ( ) )
2024-08-30 17:58:24 -04:00
. arg ( node_modules_dir_arg ( ) )
2023-08-06 21:56:56 -04:00
. arg ( vendor_arg ( ) )
2023-06-12 07:54:04 -04:00
. arg (
Arg ::new ( " json " )
. long ( " json " )
. help ( " UNSTABLE: Outputs the information in JSON format " )
. action ( ArgAction ::SetTrue ) ,
) )
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2024-08-30 17:58:24 -04:00
fn install_args ( cmd : Command ) -> Command {
let cmd = cmd . arg (
Arg ::new ( " cmd " )
. required_if_eq ( " global " , " true " )
. num_args ( 1 .. )
. value_hint ( ValueHint ::FilePath ) ,
) ;
2024-05-08 15:34:46 -04:00
cmd
. arg (
Arg ::new ( " name " )
. long ( " name " )
. short ( 'n' )
2024-08-18 18:39:53 -04:00
. help ( " Executable file name " ) ,
2024-05-08 15:34:46 -04:00
)
. arg (
Arg ::new ( " root " )
. long ( " root " )
. help ( " Installation root " )
. value_hint ( ValueHint ::DirPath ) ,
)
. arg (
Arg ::new ( " force " )
. long ( " force " )
. short ( 'f' )
. help ( " Forcefully overwrite existing installation " )
. action ( ArgAction ::SetTrue ) ,
)
. arg (
Arg ::new ( " global " )
. long ( " global " )
. short ( 'g' )
. help ( " Install a package or script as a globally available executable " )
. action ( ArgAction ::SetTrue ) ,
)
. arg ( env_file_arg ( ) )
}
fn future_install_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " install " , " Installs dependencies either in the local project or globally to a bin directory.
2024-05-08 15:34:46 -04:00
Local installation
- - - - - - - - - - - - - - - - - - -
If the - - global flag is not set , adds dependencies to the local project ' s configuration
( package . json / deno . json ) and installs them in the package cache . If no dependency
is specified , installs all dependencies listed in package . json .
deno install
deno install @ std / bytes
deno install npm :chalk
Global installation
- - - - - - - - - - - - - - - - - - -
If the - - global flag is set , installs a script as an executable in the installation root ' s bin directory .
deno install - - global - - allow - net - - allow - read jsr :@ std / http / file - server
deno install - g https ://examples.deno.land/color-logging.ts
To change the executable name , use - n / - - name :
deno install - g - - allow - net - - allow - read - n serve jsr :@ std / http / file - server
The executable name is inferred by default :
- Attempt to take the file stem of the URL path . The above example would
become ' file_server ' .
- If the file stem is something generic like ' main ' , ' mod ' , ' index ' or ' cli ' ,
and the path has no parent , take the file name of the parent path . Otherwise
settle with the generic name .
- If the resulting name has an ' @ .. . ' suffix , strip it .
To change the installation root , use - - root :
deno install - g - - allow - net - - allow - read - - root / usr / local jsr :@ std / http / file - server
The installation root is determined , in order of precedence :
- - - root option
- DENO_INSTALL_ROOT environment variable
- $HOME / . deno
2024-08-18 18:39:53 -04:00
These must be added to the path manually if required . " , UnstableArgsConfig::ResolutionAndRuntime)
. visible_alias ( " i " )
2024-05-08 15:34:46 -04:00
. defer ( | cmd | {
2024-08-12 11:55:33 -04:00
let cmd = runtime_args ( cmd , true , true ) . arg ( check_arg ( true ) ) . arg ( allow_scripts_arg ( ) ) ;
2024-08-30 17:58:24 -04:00
install_args ( cmd )
2024-05-08 15:34:46 -04:00
} )
2023-06-27 20:57:20 -04:00
}
2024-08-12 11:55:33 -04:00
fn json_reference_subcommand ( ) -> Command {
Command ::new ( " json_reference " ) . hide ( true )
}
2023-09-15 20:42:09 -04:00
fn jupyter_subcommand ( ) -> Command {
Command ::new ( " jupyter " )
. arg (
Arg ::new ( " install " )
. long ( " install " )
. help ( " Installs kernelspec, requires 'jupyter' command to be available. " )
. conflicts_with ( " kernel " )
. action ( ArgAction ::SetTrue )
)
. arg (
Arg ::new ( " kernel " )
. long ( " kernel " )
. help ( " Start the kernel " )
. conflicts_with ( " install " )
. requires ( " conn " )
. action ( ArgAction ::SetTrue )
)
. arg (
Arg ::new ( " conn " )
. long ( " conn " )
. help ( " Path to JSON file describing connection parameters, provided by Jupyter " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2023-09-15 20:42:09 -04:00
. value_hint ( ValueHint ::FilePath )
. conflicts_with ( " install " ) )
. about ( " Deno kernel for Jupyter notebooks " )
}
2023-06-27 20:57:20 -04:00
fn uninstall_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" uninstall " ,
" Uninstalls an executable script in the installation root's bin directory.
2021-09-30 11:38:07 -04:00
deno uninstall serve
To change the installation root , use - - root :
deno uninstall - - root / usr / local serve
The installation root is determined , in order of precedence :
- - - root option
- DENO_INSTALL_ROOT environment variable
2024-08-18 18:39:53 -04:00
- $HOME / . deno " ,
UnstableArgsConfig ::None ,
)
. defer ( | cmd | {
cmd
. arg ( Arg ::new ( " name " ) . required_unless_present ( " help " ) )
2023-06-27 20:57:20 -04:00
. arg (
Arg ::new ( " root " )
. long ( " root " )
. help ( " Installation root " )
2024-08-18 18:39:53 -04:00
. value_hint ( ValueHint ::DirPath ) ,
2024-03-27 18:45:57 -04:00
)
. arg (
Arg ::new ( " global " )
. long ( " global " )
. short ( 'g' )
. help ( " Remove globally installed package or module " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue ) ,
2024-03-27 18:45:57 -04:00
)
2024-08-18 18:39:53 -04:00
} )
2021-09-30 11:38:07 -04:00
}
2024-08-18 18:39:53 -04:00
fn lsp_subcommand ( ) -> Command {
Command ::new ( " lsp " ) . about (
" The 'deno lsp' subcommand provides a way for code editors and IDEs to
2021-04-16 09:28:41 -04:00
interact with Deno using the Language Server Protocol . Usually humans do not
use this subcommand directly . For example , ' deno lsp ' can provide IDEs with
go - to - definition support and automatic code formatting .
How to connect various editors and IDEs to ' deno lsp ' :
2024-08-18 18:39:53 -04:00
https ://docs.deno.com/go/lsp",
)
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn lint_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" lint " ,
" Lint JavaScript/TypeScript source code.
2021-04-18 09:12:55 -04:00
2021-04-27 06:44:36 -04:00
deno lint
deno lint myfile1 . ts myfile2 . js
2021-04-16 09:28:41 -04:00
Print result as JSON :
2021-04-27 06:44:36 -04:00
deno lint - - json
2021-04-16 09:28:41 -04:00
Read from stdin :
2021-04-27 06:44:36 -04:00
cat file . ts | deno lint -
cat file . ts | deno lint - - json -
2021-04-16 09:28:41 -04:00
List available rules :
2021-04-27 06:44:36 -04:00
deno lint - - rules
2021-04-16 09:28:41 -04:00
Ignore diagnostics on the next line by preceding it with an ignore comment and
rule name :
2021-04-18 09:12:55 -04:00
// deno-lint-ignore no-explicit-any
2021-04-16 09:28:41 -04:00
// deno-lint-ignore require-await no-empty
Names of rules to ignore must be specified after ignore comment .
Ignore linting a file by adding an ignore comment at the top of the file :
// deno-lint-ignore-file
" ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionOnly ,
)
. defer ( | cmd | {
cmd
. arg (
Arg ::new ( " fix " )
. long ( " fix " )
. help ( " Fix any linting errors for rules that support it " )
. action ( ArgAction ::SetTrue )
. help_heading ( LINT_HEADING ) ,
)
. arg (
2024-08-19 16:42:13 -04:00
Arg ::new ( " ext " )
. long ( " ext " )
. require_equals ( true )
. value_name ( " EXT " )
. help ( " Specify the file extension to lint when reading from stdin. \
For example , use ` jsx ` to lint JSX files or ` tsx ` for TSX files . \
This argument is necessary because stdin input does not automatically infer the file type . \
Example usage : ` cat file . jsx | deno lint - - - ext = jsx ` . " ),
)
. arg (
2024-08-18 18:39:53 -04:00
Arg ::new ( " rules " )
. long ( " rules " )
. help ( " List available rules " )
. action ( ArgAction ::SetTrue )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " rules-tags " )
. long ( " rules-tags " )
. require_equals ( true )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. use_value_delimiter ( true )
. help ( " Use set of rules with a tag " )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " rules-include " )
. long ( " rules-include " )
. require_equals ( true )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. conflicts_with ( " rules " )
. help ( " Include lint rules " )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " rules-exclude " )
. long ( " rules-exclude " )
. require_equals ( true )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. conflicts_with ( " rules " )
. help ( " Exclude lint rules " )
. help_heading ( LINT_HEADING ) ,
)
. arg ( no_config_arg ( ) )
. arg ( config_arg ( ) )
. arg (
Arg ::new ( " ignore " )
. long ( " ignore " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. help ( " Ignore linting particular source files " )
. value_hint ( ValueHint ::AnyPath )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " json " )
. long ( " json " )
. help ( " Output lint result in JSON format " )
. action ( ArgAction ::SetTrue )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " compact " )
. long ( " compact " )
. help ( " Output lint result in compact format " )
. action ( ArgAction ::SetTrue )
. conflicts_with ( " json " )
. help_heading ( LINT_HEADING ) ,
)
. arg (
Arg ::new ( " files " )
. num_args ( 1 .. )
. action ( ArgAction ::Append )
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg ( watch_arg ( false ) )
. arg ( watch_exclude_arg ( ) )
. arg ( no_clear_screen_arg ( ) )
} )
2021-04-16 09:28:41 -04:00
}
2019-05-16 10:39:19 -04:00
2023-03-26 00:06:18 -04:00
fn repl_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " repl " , " Read Eval Print Loop " , UnstableArgsConfig ::ResolutionAndRuntime )
2024-08-12 11:55:33 -04:00
. defer ( | cmd | runtime_args ( cmd , true , true )
2023-06-12 07:54:04 -04:00
. arg ( check_arg ( false ) )
. arg (
Arg ::new ( " eval-file " )
. long ( " eval-file " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
2024-08-21 09:54:59 -04:00
. help ( " Evaluates the provided file(s) as scripts when the REPL starts. Accepts file paths and URLs " )
2023-06-12 07:54:04 -04:00
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg (
Arg ::new ( " eval " )
. long ( " eval " )
2024-08-21 09:54:59 -04:00
. help ( " Evaluates the provided code when the REPL starts " )
2023-06-12 07:54:04 -04:00
. value_name ( " code " ) ,
2024-08-18 18:39:53 -04:00
)
2024-08-21 09:54:59 -04:00
. after_help ( cstr! ( " <y>Environment variables:</>
2024-08-18 18:39:53 -04:00
< g > DENO_REPL_HISTORY < / > Set REPL history file path . History file is disabled when the value is empty .
2024-08-21 09:54:59 -04:00
< p ( 245 ) > [ default : $DENO_DIR / deno_history . txt ] < / > " ))
2024-08-18 18:39:53 -04:00
)
2024-08-12 11:55:33 -04:00
. arg ( env_file_arg ( ) )
2019-11-26 11:06:32 -05:00
}
2024-08-08 10:22:28 -04:00
fn run_args ( command : Command , top_level : bool ) -> Command {
2024-08-12 11:55:33 -04:00
runtime_args ( command , true , true )
. arg ( check_arg ( false ) )
. arg ( watch_arg ( true ) )
. arg ( hmr_arg ( true ) )
2024-08-18 18:39:53 -04:00
. arg ( watch_exclude_arg ( ) )
2024-08-12 11:55:33 -04:00
. arg ( no_clear_screen_arg ( ) )
. arg ( executable_ext_arg ( ) )
2024-08-08 10:22:28 -04:00
. arg ( if top_level {
script_arg ( ) . trailing_var_arg ( true ) . hide ( true )
} else {
2024-08-21 09:54:59 -04:00
script_arg ( ) . trailing_var_arg ( true )
2024-08-08 10:22:28 -04:00
} )
2024-08-12 11:55:33 -04:00
. arg ( env_file_arg ( ) )
. arg ( no_code_cache_arg ( ) )
2024-08-08 10:22:28 -04:00
}
fn run_subcommand ( ) -> Command {
2024-08-21 09:54:59 -04:00
run_args ( command ( " run " , cstr! ( " Run a JavaScript or TypeScript program, or a task or script.
2021-04-18 09:12:55 -04:00
2024-08-12 11:55:33 -04:00
By default all programs are run in sandbox without access to disk , network or ability to spawn subprocesses .
< p ( 245 ) > deno run https ://examples.deno.land/hello-world.ts</>
2021-04-16 09:28:41 -04:00
Grant permission to read from disk and listen to network :
2024-08-12 11:55:33 -04:00
< p ( 245 ) > deno run - - allow - read - - allow - net jsr :@ std / http / file - server < / >
2021-04-16 09:28:41 -04:00
Grant permission to read allow - listed files from disk :
2024-08-12 11:55:33 -04:00
< p ( 245 ) > deno run - - allow - read = / etc jsr :@ std / http / file - server < / >
2021-04-18 09:12:55 -04:00
2024-08-12 11:55:33 -04:00
Grant all permissions :
< p ( 245 ) > deno run - A jsr :@ std / http / file - server < / >
2021-04-16 09:28:41 -04:00
2022-04-11 01:01:02 -04:00
Specifying the filename '-' to read the file from stdin .
2024-08-18 18:39:53 -04:00
< p ( 245 ) > curl https ://examples.deno.land/hello-world.ts | deno run -</>"), UnstableArgsConfig::ResolutionAndRuntime), false)
2021-04-16 09:28:41 -04:00
}
2024-04-24 15:45:49 -04:00
fn serve_host_validator ( host : & str ) -> Result < String , String > {
if Url ::parse ( & format! ( " internal:// {host} :9999 " ) ) . is_ok ( ) {
Ok ( host . to_owned ( ) )
} else {
Err ( format! ( " Bad serve host: {host} " ) )
}
}
fn serve_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
runtime_args ( command ( " serve " , None , UnstableArgsConfig ::ResolutionAndRuntime ) , true , true )
2024-04-24 15:45:49 -04:00
. arg (
Arg ::new ( " port " )
. long ( " port " )
2024-08-21 09:54:59 -04:00
. help ( " The TCP port to serve on, defaulting to 8000. Pass 0 to pick a random free port " )
2024-05-17 01:38:50 -04:00
. value_parser ( value_parser! ( u16 ) ) ,
2024-04-24 15:45:49 -04:00
)
. arg (
Arg ::new ( " host " )
. long ( " host " )
2024-08-21 09:54:59 -04:00
. help ( " The TCP address to serve on, defaulting to 0.0.0.0 (all interfaces) " )
2024-04-24 15:45:49 -04:00
. value_parser ( serve_host_validator ) ,
)
2024-08-14 18:26:21 -04:00
. arg (
2024-09-02 11:26:42 -04:00
parallel_arg ( " multiple server workers " )
2024-08-14 18:26:21 -04:00
)
2024-04-24 15:45:49 -04:00
. arg ( check_arg ( false ) )
. arg ( watch_arg ( true ) )
. arg ( hmr_arg ( true ) )
2024-08-18 18:39:53 -04:00
. arg ( watch_exclude_arg ( ) )
2024-04-24 15:45:49 -04:00
. arg ( no_clear_screen_arg ( ) )
. arg ( executable_ext_arg ( ) )
. arg (
script_arg ( )
2024-08-18 18:39:53 -04:00
. required_unless_present_any ( [ " help " , " v8-flags " ] )
2024-04-24 15:45:49 -04:00
. trailing_var_arg ( true ) ,
)
. arg ( env_file_arg ( ) )
. arg ( no_code_cache_arg ( ) )
2024-08-12 11:55:33 -04:00
. about ( " Run a server defined in a main module
2024-04-24 15:45:49 -04:00
The serve command uses the default exports of the main module to determine which
servers to start .
See https ://docs.deno.com/runtime/manual/tools/serve for
more detailed information .
Start a server defined in server . ts :
deno serve server . ts
Start a server defined in server . ts , watching for changes and running on port 5050 :
deno serve - - watch - - port 5050 server . ts " )
}
2023-03-26 00:06:18 -04:00
fn task_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" task " ,
" Run a task defined in the configuration file
2022-03-10 20:56:14 -05:00
deno task build " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionAndRuntime ,
)
. defer ( | cmd | {
cmd
. allow_external_subcommands ( true )
. subcommand_value_name ( " TASK " )
. arg ( config_arg ( ) )
. arg (
Arg ::new ( " cwd " )
. long ( " cwd " )
. value_name ( " DIR " )
. help ( " Specify the directory to run the task in " )
. value_hint ( ValueHint ::DirPath ) ,
)
} )
2022-03-10 20:56:14 -05:00
}
2023-03-26 00:06:18 -04:00
fn test_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " test " ,
2023-06-27 20:57:20 -04:00
" Run tests using Deno's built-in test runner.
Evaluate the given modules , run all tests declared with ' Deno . test ( ) ' and
report results to standard output :
deno test src / fetch_test . ts src / signal_test . ts
Directory arguments are expanded to all contained files matching the glob
2024-07-08 09:19:59 -04:00
{ * _ , * . , } test . { js , mjs , ts , mts , jsx , tsx } or * * / __tests__ /**:
2023-06-27 20:57:20 -04:00
deno test src / " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionAndRuntime
2023-06-27 20:57:20 -04:00
)
2024-08-18 18:39:53 -04:00
. defer ( | cmd |
runtime_args ( cmd , true , true )
2024-08-12 11:55:33 -04:00
. arg ( check_arg ( true ) )
. arg (
Arg ::new ( " ignore " )
. long ( " ignore " )
. num_args ( 1 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. help ( " Ignore files " )
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg (
Arg ::new ( " no-run " )
. long ( " no-run " )
. help ( " Cache test modules, but don't run tests " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " trace-leaks " )
. long ( " trace-leaks " )
2024-08-21 09:54:59 -04:00
. help ( " Enable tracing of leaks. Useful when debugging leaking ops in test, but impacts test execution time " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " doc " )
. long ( " doc " )
. help ( " Type-check code blocks in JSDoc and Markdown " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " fail-fast " )
. long ( " fail-fast " )
. alias ( " failfast " )
2024-08-21 09:54:59 -04:00
. help ( " Stop after N errors. Defaults to stopping after first failure " )
2024-08-12 11:55:33 -04:00
. num_args ( 0 ..= 1 )
. require_equals ( true )
. value_name ( " N " )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( NonZeroUsize ) )
. help_heading ( TEST_HEADING ) )
2024-08-12 11:55:33 -04:00
. arg (
Arg ::new ( " permit-no-files " )
. long ( " permit-no-files " )
. help ( " Don't return an error code if no test files were found " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " filter " )
. allow_hyphen_values ( true )
. long ( " filter " )
2024-08-21 09:54:59 -04:00
. help ( " Run tests with this string or regexp pattern in the test name " )
2024-08-18 18:39:53 -04:00
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " shuffle " )
. long ( " shuffle " )
. value_name ( " NUMBER " )
. help ( " Shuffle the order in which the tests are run " )
. num_args ( 0 ..= 1 )
. require_equals ( true )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( u64 ) )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " coverage " )
. long ( " coverage " )
. value_name ( " DIR " )
. num_args ( 0 ..= 1 )
. require_equals ( true )
. default_missing_value ( " coverage " )
. conflicts_with ( " inspect " )
. conflicts_with ( " inspect-wait " )
. conflicts_with ( " inspect-brk " )
2024-08-21 09:54:59 -04:00
. help ( " Collect coverage profile data into DIR. If DIR is not specified, it uses 'coverage/' " )
2024-08-18 18:39:53 -04:00
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " clean " )
. long ( " clean " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Empty the temporary coverage profile data directory before running tests.
< p ( 245 ) > Note : running multiple ` deno test - - clean ` calls in series or parallel for the same coverage directory may cause race conditions . < / > " ))
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( TEST_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
2024-09-02 11:26:42 -04:00
parallel_arg ( " test modules " )
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " files " )
. help ( " List of file names to run " )
. num_args ( 0 .. )
. action ( ArgAction ::Append )
. value_hint ( ValueHint ::AnyPath ) ,
)
. arg (
2024-08-19 13:09:51 -04:00
watch_arg ( true )
2024-08-12 11:55:33 -04:00
. conflicts_with ( " no-run " )
. conflicts_with ( " coverage " ) ,
)
. arg ( watch_exclude_arg ( ) )
. arg ( no_clear_screen_arg ( ) )
. arg ( script_arg ( ) . last ( true ) )
. arg (
Arg ::new ( " junit-path " )
. long ( " junit-path " )
. value_name ( " PATH " )
. value_hint ( ValueHint ::FilePath )
2024-08-21 09:54:59 -04:00
. help ( " Write a JUnit XML test report to PATH. Use '-' to write to stdout which is the default when PATH is not provided " )
2024-08-18 18:39:53 -04:00
. help_heading ( TEST_HEADING )
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " reporter " )
. long ( " reporter " )
2024-08-21 09:54:59 -04:00
. help ( " Select reporter to use. Default to 'pretty' " )
2024-08-12 11:55:33 -04:00
. value_parser ( [ " pretty " , " dot " , " junit " , " tap " ] )
2024-08-18 18:39:53 -04:00
. help_heading ( TEST_HEADING )
2024-08-12 11:55:33 -04:00
)
2024-08-19 21:27:36 -04:00
. arg (
Arg ::new ( " hide-stacktraces " )
. long ( " hide-stacktraces " )
. help ( " Hide stack traces for errors in failure test results. " )
. action ( ArgAction ::SetTrue )
)
2024-08-12 11:55:33 -04:00
. arg ( env_file_arg ( ) )
2023-08-02 12:38:10 -04:00
)
2019-06-05 13:44:46 -04:00
}
2024-09-02 11:26:42 -04:00
fn parallel_arg ( descr : & str ) -> Arg {
Arg ::new ( " parallel " )
2024-08-14 18:26:21 -04:00
. long ( " parallel " )
2024-08-21 09:54:59 -04:00
. help ( format! ( " Run {descr} in parallel. Parallelism defaults to the number of available CPUs or the value of the DENO_JOBS environment variable " ) )
2024-09-02 11:26:42 -04:00
. action ( ArgAction ::SetTrue )
2024-08-14 18:26:21 -04:00
}
2023-03-26 00:06:18 -04:00
fn types_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" types " ,
2024-08-12 11:55:33 -04:00
" Print runtime TypeScript declarations.
2021-04-18 09:12:55 -04:00
2021-04-16 09:28:41 -04:00
deno types > lib . deno . d . ts
2021-02-24 09:27:51 -05:00
2021-04-16 09:28:41 -04:00
The declaration file could be saved and used for typing information . " ,
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
2024-08-12 11:55:33 -04:00
)
2021-04-16 09:28:41 -04:00
}
2021-02-24 09:27:51 -05:00
2023-03-26 00:06:18 -04:00
fn upgrade_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command (
" upgrade " ,
2024-08-19 11:05:10 -04:00
color_print ::cstr! ( " <g>Upgrade</> deno executable to the given version.
< g > Latest < / >
deno upgrade
< g > Specific version < / >
deno upgrade < p ( 245 ) > 1.4 5.0 < / >
deno upgrade < p ( 245 ) > 1.4 6.0 - rc . 1 < / >
deno upgrade < p ( 245 ) > 9 bc2dd29ad6ba334fd57a20114e367d3c04763d4 < / >
< g > Channel < / >
deno upgrade < p ( 245 ) > stable < / >
deno upgrade < p ( 245 ) > rc < / >
deno upgrade < p ( 245 ) > canary < / >
2021-02-24 09:27:51 -05:00
2021-04-16 09:28:41 -04:00
The version is downloaded from
https ://github.com/denoland/deno/releases
and is used to replace the current executable .
2021-02-24 09:27:51 -05:00
2021-04-16 09:28:41 -04:00
If you want to not replace the current Deno executable but instead download an
2024-08-12 11:55:33 -04:00
update to a different location , use the - - output flag :
2024-08-19 11:05:10 -04:00
deno upgrade - - output $HOME / my_deno " ),
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::None ,
)
. hide ( cfg! ( not ( feature = " upgrade " ) ) )
. defer ( | cmd | {
cmd
. arg (
Arg ::new ( " version " )
. long ( " version " )
. help ( " The version to upgrade to " )
2024-08-19 11:05:10 -04:00
. help_heading ( UPGRADE_HEADING ) // NOTE(bartlomieju): pre-v1.46 compat
. hide ( true ) ,
2024-08-18 18:39:53 -04:00
)
. arg (
Arg ::new ( " output " )
. long ( " output " )
. help ( " The path to output the updated version to " )
. value_parser ( value_parser! ( String ) )
. value_hint ( ValueHint ::FilePath )
. help_heading ( UPGRADE_HEADING ) ,
)
. arg (
Arg ::new ( " dry-run " )
. long ( " dry-run " )
. help ( " Perform all checks without replacing old exe " )
. action ( ArgAction ::SetTrue )
. help_heading ( UPGRADE_HEADING ) ,
)
. arg (
Arg ::new ( " force " )
. long ( " force " )
. short ( 'f' )
. help ( " Replace current exe even if not out-of-date " )
. action ( ArgAction ::SetTrue )
. help_heading ( UPGRADE_HEADING ) ,
)
. arg (
Arg ::new ( " canary " )
. long ( " canary " )
. help ( " Upgrade to canary builds " )
. action ( ArgAction ::SetTrue )
2024-08-19 11:05:10 -04:00
. help_heading ( UPGRADE_HEADING ) // NOTE(bartlomieju): pre-v1.46 compat
. hide ( true ) ,
2024-08-18 18:39:53 -04:00
)
. arg (
Arg ::new ( " release-candidate " )
. long ( " rc " )
. help ( " Upgrade to a release candidate " )
. conflicts_with_all ( [ " canary " , " version " ] )
. action ( ArgAction ::SetTrue )
2024-08-19 11:05:10 -04:00
. help_heading ( UPGRADE_HEADING )
// NOTE(bartlomieju): pre-v1.46 compat
. hide ( true ) ,
)
. arg (
Arg ::new ( " version-or-hash-or-channel " )
. help ( color_print ::cstr! ( " Version <p(245)>(v1.46.0)</>, channel <p(245)>(rc, canary)</> or commit hash <p(245)>(9bc2dd29ad6ba334fd57a20114e367d3c04763d4)</> " ) )
. value_name ( " VERSION " )
. action ( ArgAction ::Append )
. trailing_var_arg ( true ) ,
2024-08-18 18:39:53 -04:00
)
. arg ( ca_file_arg ( ) )
. arg ( unsafely_ignore_certificate_errors_arg ( ) )
} )
2020-03-23 11:37:24 -04:00
}
2023-03-26 00:06:18 -04:00
fn vendor_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " vendor " ,
2024-09-03 03:00:57 -04:00
" ⚠️ `deno vendor` was removed in Deno 2.
2022-02-16 13:14:19 -05:00
2024-09-03 03:00:57 -04:00
See the Deno 1. x to 2. x Migration Guide for migration instructions : https ://docs.deno.com/runtime/manual/advanced/migrate_deprecations",
2024-08-18 18:39:53 -04:00
UnstableArgsConfig ::ResolutionOnly
2024-08-12 11:55:33 -04:00
)
2024-08-18 18:39:53 -04:00
. hide ( true )
2022-02-16 13:14:19 -05:00
}
2023-11-23 18:38:07 -05:00
fn publish_subcommand ( ) -> Command {
2024-08-18 18:39:53 -04:00
command ( " publish " , " Publish the current working directory's package or workspace " , UnstableArgsConfig ::ResolutionOnly )
2023-11-23 18:38:07 -05:00
. defer ( | cmd | {
2024-08-18 18:39:53 -04:00
cmd
. arg (
2023-11-23 18:38:07 -05:00
Arg ::new ( " token " )
2023-11-24 08:05:47 -05:00
. long ( " token " )
. help ( " The API token to use when publishing. If unset, interactive authentication is be used " )
2024-08-18 18:39:53 -04:00
. help_heading ( PUBLISH_HEADING )
2023-11-23 18:38:07 -05:00
)
2024-08-12 11:55:33 -04:00
. arg ( config_arg ( ) )
. arg ( no_config_arg ( ) )
. arg (
Arg ::new ( " dry-run " )
. long ( " dry-run " )
. help ( " Prepare the package for publishing performing all checks and validations without uploading " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( PUBLISH_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " allow-slow-types " )
. long ( " allow-slow-types " )
. help ( " Allow publishing with slow types " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( PUBLISH_HEADING ) ,
2024-08-12 11:55:33 -04:00
)
. arg (
Arg ::new ( " allow-dirty " )
. long ( " allow-dirty " )
. help ( " Allow publishing if the repository has uncommitted changed " )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. help_heading ( PUBLISH_HEADING ) ,
2024-08-12 11:55:33 -04:00
) . arg (
2024-02-29 11:18:47 -05:00
Arg ::new ( " no-provenance " )
. long ( " no-provenance " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Disable provenance attestation.
< p ( 245 ) > Enabled by default on Github actions , publicly links the package to where it was built and published from . < / > " ))
2024-02-27 21:28:02 -05:00
. action ( ArgAction ::SetTrue )
2024-08-18 18:39:53 -04:00
. help_heading ( PUBLISH_HEADING )
2024-02-27 21:28:02 -05:00
)
2024-08-12 11:55:33 -04:00
. arg ( check_arg ( /* type checks by default */ true ) )
. arg ( no_check_arg ( ) )
2023-11-23 18:38:07 -05:00
} )
}
2024-08-12 11:55:33 -04:00
fn compile_args ( app : Command ) -> Command {
compile_args_without_check_args ( app . arg ( no_check_arg ( ) ) )
2020-06-08 08:06:20 -04:00
}
2024-08-12 11:55:33 -04:00
fn compile_args_without_check_args ( app : Command ) -> Command {
2022-04-10 19:12:51 -04:00
app
2024-08-12 11:55:33 -04:00
. arg ( import_map_arg ( ) )
. arg ( no_remote_arg ( ) )
. arg ( no_npm_arg ( ) )
2024-08-30 17:58:24 -04:00
. arg ( node_modules_dir_arg ( ) )
2024-08-12 11:55:33 -04:00
. arg ( vendor_arg ( ) )
. arg ( config_arg ( ) )
. arg ( no_config_arg ( ) )
. arg ( reload_arg ( ) )
. arg ( lock_arg ( ) )
. arg ( no_lock_arg ( ) )
. arg ( ca_file_arg ( ) )
2024-08-18 18:39:53 -04:00
. arg ( unsafely_ignore_certificate_errors_arg ( ) )
2022-04-10 19:12:51 -04:00
}
2024-08-12 11:55:33 -04:00
fn permission_args ( app : Command ) -> Command {
2019-11-26 11:06:32 -05:00
app
2024-08-21 09:54:59 -04:00
. after_help ( cstr! ( r #" <y>Permission options:</>
Docs : < c > https ://docs.deno.com/go/permissions</>
< g > - A , - - allow - all < / > Allow all permissions .
< g > - - no - prompt < / > Always throw if required permission wasn ' t passed .
< p ( 245 ) > Can also be set via the DENO_NO_PROMPT environment variable . < / >
< g > - R , - - allow - read [ = < < PATH > .. . ] < / > Allow file system read access . Optionally specify allowed paths .
< p ( 245 ) > - - allow - read | - - allow - read = " /etc,/var/log.txt " < / >
< g > - W , - - allow - write [ = < < PATH > .. . ] < / > Allow file system write access . Optionally specify allowed paths .
< p ( 245 ) > - - allow - write | - - allow - write = " /etc,/var/log.txt " < / >
< g > - N , - - allow - net [ = < < IP_OR_HOSTNAME > .. . ] < / > Allow network access . Optionally specify allowed IP addresses and host names , with ports as necessary .
< p ( 245 ) > - - allow - net | - - allow - net = " localhost:8080,deno.land " < / >
< g > - E , - - allow - env [ = < < VARIABLE_NAME > .. . ] < / > Allow access to environment variables . Optionally specify accessible environment variables .
< p ( 245 ) > - - allow - env | - - allow - env = " PORT,HOME,PATH " < / >
< g > - S , - - allow - sys [ = < < API_NAME > .. . ] < / > Allow access to OS information . Optionally allow specific APIs by function name .
< p ( 245 ) > - - allow - sys | - - allow - sys = " systemMemoryInfo,osRelease " < / >
< g > - - allow - run [ = < < PROGRAM_NAME > .. . ] < / > Allow running subprocesses . Optionally specify allowed runnable program names .
< p ( 245 ) > - - allow - run | - - allow - run = " whoami,ps " < / >
< g > - - allow - ffi [ = < < PATH > .. . ] < / > ( Unstable ) Allow loading dynamic libraries . Optionally specify allowed directories or files .
< p ( 245 ) > - - allow - ffi | - - allow - ffi = " ./libfoo.so " < / >
< g > - - deny - read [ = < < PATH > .. . ] < / > Deny file system read access . Optionally specify denied paths .
< p ( 245 ) > - - deny - read | - - deny - read = " /etc,/var/log.txt " < / >
< g > - - deny - write [ = < < PATH > .. . ] < / > Deny file system write access . Optionally specify denied paths .
< p ( 245 ) > - - deny - write | - - deny - write = " /etc,/var/log.txt " < / >
< g > - - deny - net [ = < < IP_OR_HOSTNAME > .. . ] < / > Deny network access . Optionally specify defined IP addresses and host names , with ports as necessary .
< p ( 245 ) > - - deny - net | - - deny - net = " localhost:8080,deno.land " < / >
< g > - - deny - env [ = < < VARIABLE_NAME > .. . ] < / > Deny access to environment variables . Optionally specify inacessible environment variables .
< p ( 245 ) > - - deny - env | - - deny - env = " PORT,HOME,PATH " < / >
< g > - S , - - deny - sys [ = < < API_NAME > .. . ] < / > Deny access to OS information . Optionally deny specific APIs by function name .
< p ( 245 ) > - - deny - sys | - - deny - sys = " systemMemoryInfo,osRelease " < / >
< g > - - deny - run [ = < < PROGRAM_NAME > .. . ] < / > Deny running subprocesses . Optionally specify denied runnable program names .
< p ( 245 ) > - - deny - run | - - deny - run = " whoami,ps " < / >
< g > - - deny - ffi [ = < < PATH > .. . ] < / > ( Unstable ) Deny loading dynamic libraries . Optionally specify denied directories or files .
< p ( 245 ) > - - deny - ffi | - - deny - ffi = " ./libfoo.so " < / >
2024-08-18 18:39:53 -04:00
" #))
. arg (
Arg ::new ( " allow-all " )
. short ( 'A' )
. long ( " allow-all " )
. action ( ArgAction ::SetTrue )
2024-08-21 09:54:59 -04:00
. help ( " Allow all permissions " )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
)
2019-11-26 11:06:32 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-read " )
2019-11-26 11:06:32 -05:00
. long ( " allow-read " )
2024-08-08 09:46:10 -04:00
. short ( 'R' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2019-11-26 11:06:32 -05:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " Allow file system read access. Optionally specify allowed paths " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-read " )
. long ( " deny-read " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " Deny file system read access. Optionally specify denied paths " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2019-11-26 11:06:32 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-write " )
2019-11-26 11:06:32 -05:00
. long ( " allow-write " )
2024-08-08 09:46:10 -04:00
. short ( 'W' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2019-11-26 11:06:32 -05:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " Allow file system write access. Optionally specify allowed paths " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-write " )
. long ( " deny-write " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " Deny file system write access. Optionally specify denied paths " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2019-11-26 11:06:32 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-net " )
2019-11-26 11:06:32 -05:00
. long ( " allow-net " )
2024-08-08 09:46:10 -04:00
. short ( 'N' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2019-11-26 11:06:32 -05:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " IP_OR_HOSTNAME " )
2024-08-21 09:54:59 -04:00
. help ( " Allow network access. Optionally specify allowed IP addresses and host names, with ports as necessary " )
2024-08-08 10:22:28 -04:00
. value_parser ( flags_net ::validator )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
. arg (
Arg ::new ( " deny-net " )
. long ( " deny-net " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " IP_OR_HOSTNAME " )
2024-08-21 09:54:59 -04:00
. help ( " Deny network access. Optionally specify denied IP addresses and host names, with ports as necessary " )
2024-08-08 10:22:28 -04:00
. value_parser ( flags_net ::validator )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-env " )
2019-11-26 11:06:32 -05:00
. long ( " allow-env " )
2024-08-08 09:46:10 -04:00
. short ( 'E' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-04-13 07:25:21 -04:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " VARIABLE_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Allow access to system environment information. Optionally specify accessible environment variables " )
2023-03-26 00:06:18 -04:00
. value_parser ( | key : & str | {
if key . is_empty ( ) | | key . contains ( & [ '=' , '\0' ] as & [ char ] ) {
return Err ( format! ( " invalid key \" {key} \" " ) ) ;
2021-04-13 07:25:21 -04:00
}
2023-03-26 00:06:18 -04:00
Ok ( if cfg! ( windows ) {
key . to_uppercase ( )
} else {
key . to_string ( )
} )
2024-08-08 10:22:28 -04:00
} )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-env " )
. long ( " deny-env " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " VARIABLE_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Deny access to system environment information. Optionally specify accessible environment variables " )
2023-08-03 07:19:19 -04:00
. value_parser ( | key : & str | {
if key . is_empty ( ) | | key . contains ( & [ '=' , '\0' ] as & [ char ] ) {
return Err ( format! ( " invalid key \" {key} \" " ) ) ;
}
Ok ( if cfg! ( windows ) {
key . to_uppercase ( )
} else {
key . to_string ( )
} )
2024-08-08 10:22:28 -04:00
} )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2022-09-28 08:46:50 -04:00
. arg (
Arg ::new ( " allow-sys " )
. long ( " allow-sys " )
2024-08-08 09:46:10 -04:00
. short ( 'S' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-09-28 08:46:50 -04:00
. use_value_delimiter ( true )
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " API_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Allow access to OS information. Optionally allow specific APIs by function name " )
2024-08-08 10:22:28 -04:00
. value_parser ( | key : & str | parse_sys_kind ( key ) . map ( ToString ::to_string ) )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2022-09-28 08:46:50 -04:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-sys " )
. long ( " deny-sys " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " API_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Deny access to OS information. Optionally deny specific APIs by function name " )
2024-08-08 10:22:28 -04:00
. value_parser ( | key : & str | parse_sys_kind ( key ) . map ( ToString ::to_string ) )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2019-11-26 11:06:32 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-run " )
2019-11-26 11:06:32 -05:00
. long ( " allow-run " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-04-09 18:12:00 -04:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " PROGRAM_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Allow running subprocesses. Optionally specify allowed runnable program names " )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-run " )
. long ( " deny-run " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " PROGRAM_NAME " )
2024-08-21 09:54:59 -04:00
. help ( " Deny running subprocesses. Optionally specify denied runnable program names " )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2019-12-05 15:30:20 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-ffi " )
2021-08-06 17:28:10 -04:00
. long ( " allow-ffi " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-08-06 17:28:10 -04:00
. require_equals ( true )
2023-04-26 20:49:59 -04:00
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " (Unstable) Allow loading dynamic libraries. Optionally specify allowed directories or files " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-12-05 15:30:20 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-ffi " )
. long ( " deny-ffi " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " PATH " )
2024-08-21 09:54:59 -04:00
. help ( " (Unstable) Deny loading dynamic libraries. Optionally specify denied directories or files " )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2024-08-08 10:22:28 -04:00
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2023-08-03 07:19:19 -04:00
)
2019-11-26 11:06:32 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " allow-hrtime " )
2019-11-26 11:06:32 -05:00
. long ( " allow-hrtime " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2024-09-03 05:24:25 -04:00
. help ( " REMOVED in Deno 2.0 " )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2023-08-03 07:19:19 -04:00
. arg (
Arg ::new ( " deny-hrtime " )
. long ( " deny-hrtime " )
. action ( ArgAction ::SetTrue )
2024-09-03 05:24:25 -04:00
. help ( " REMOVED in Deno 2.0 " )
2024-08-18 18:39:53 -04:00
. hide ( true ) ,
2019-11-26 11:06:32 -05:00
)
2021-04-11 22:15:43 -04:00
. arg (
2022-02-12 22:13:21 -05:00
Arg ::new ( " no-prompt " )
. long ( " no-prompt " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2024-08-18 18:39:53 -04:00
. hide ( true )
. help ( " Always throw if required permission wasn't passed " ) ,
2021-04-11 22:15:43 -04:00
)
2020-01-30 18:42:39 -05:00
}
2022-03-27 21:57:56 -04:00
fn runtime_args (
app : Command ,
include_perms : bool ,
include_inspector : bool ,
) -> Command {
2024-08-12 11:55:33 -04:00
let app = compile_args ( app ) ;
2021-04-16 09:28:41 -04:00
let app = if include_perms {
2024-08-12 11:55:33 -04:00
permission_args ( app )
2021-04-16 09:28:41 -04:00
} else {
app
} ;
let app = if include_inspector {
2024-08-12 11:55:33 -04:00
inspect_args ( app )
2021-04-16 09:28:41 -04:00
} else {
app
} ;
app
2024-08-12 11:55:33 -04:00
. arg ( frozen_lockfile_arg ( ) )
. arg ( cached_only_arg ( ) )
. arg ( location_arg ( ) )
. arg ( v8_flags_arg ( ) )
. arg ( seed_arg ( ) )
2021-07-23 10:31:16 -04:00
. arg ( enable_testing_features_arg ( ) )
2023-11-10 12:41:24 -05:00
. arg ( strace_ops_arg ( ) )
2021-04-16 09:28:41 -04:00
}
2024-08-12 11:55:33 -04:00
fn inspect_args ( app : Command ) -> Command {
2021-04-16 09:28:41 -04:00
app
2020-12-11 07:18:30 -05:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " inspect " )
2021-04-16 09:28:41 -04:00
. long ( " inspect " )
2023-01-09 07:29:43 -05:00
. value_name ( " HOST_AND_PORT " )
2024-08-21 09:54:59 -04:00
. default_missing_value ( " 127.0.0.1:9229 " )
. help ( cstr! ( " Activate inspector on host:port <p(245)>[default: 127.0.0.1:9229]</> " ) )
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2021-04-16 09:28:41 -04:00
. require_equals ( true )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( SocketAddr ) )
. help_heading ( DEBUGGING_HEADING ) ,
2020-12-11 07:18:30 -05:00
)
2020-10-25 20:25:43 -04:00
. arg (
2022-01-14 11:38:17 -05:00
Arg ::new ( " inspect-brk " )
2021-04-16 09:28:41 -04:00
. long ( " inspect-brk " )
2023-01-09 07:29:43 -05:00
. value_name ( " HOST_AND_PORT " )
2024-08-21 09:54:59 -04:00
. default_missing_value ( " 127.0.0.1:9229 " )
2021-04-16 09:28:41 -04:00
. help (
2022-12-12 09:33:30 -05:00
" Activate inspector on host:port, wait for debugger to connect and break at the start of user script " ,
)
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2022-12-12 09:33:30 -05:00
. require_equals ( true )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( SocketAddr ) )
. help_heading ( DEBUGGING_HEADING ) ,
2022-12-12 09:33:30 -05:00
)
. arg (
Arg ::new ( " inspect-wait " )
. long ( " inspect-wait " )
2023-01-09 07:29:43 -05:00
. value_name ( " HOST_AND_PORT " )
2024-08-21 09:54:59 -04:00
. default_missing_value ( " 127.0.0.1:9229 " )
2022-12-12 09:33:30 -05:00
. help (
" Activate inspector on host:port and wait for debugger to connect before running user code " ,
2021-04-16 09:28:41 -04:00
)
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2021-04-16 09:28:41 -04:00
. require_equals ( true )
2024-08-18 18:39:53 -04:00
. value_parser ( value_parser! ( SocketAddr ) )
. help_heading ( DEBUGGING_HEADING ) ,
2019-11-26 11:06:32 -05:00
)
2019-04-29 19:43:06 -04:00
}
2023-03-26 00:06:18 -04:00
fn import_map_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " import-map " )
2021-04-16 09:28:41 -04:00
. long ( " import-map " )
. alias ( " importmap " )
. value_name ( " FILE " )
2024-08-21 09:54:59 -04:00
. help ( cstr! (
" Load import map file from local file or remote URL
< p ( 245 ) > Docs : https ://docs.deno.com/runtime/manual/basics/import_maps</>",
) )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::FilePath )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2021-04-16 09:28:41 -04:00
}
2023-11-01 11:21:13 -04:00
fn env_file_arg ( ) -> Arg {
2024-08-08 09:50:57 -04:00
Arg ::new ( " env-file " )
. long ( " env-file " )
. alias ( " env " )
2023-11-01 11:21:13 -04:00
. value_name ( " FILE " )
2024-08-21 09:54:59 -04:00
. help ( cstr! (
" Load environment variables from local file
< p ( 245 ) > Only the first environment variable with a given key is used .
Existing process environment variables are not overwritten . < / > "
) )
2023-11-01 11:21:13 -04:00
. value_hint ( ValueHint ::FilePath )
. default_missing_value ( " .env " )
. require_equals ( true )
. num_args ( 0 ..= 1 )
}
2023-03-26 00:06:18 -04:00
fn reload_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " reload " )
. short ( 'r' )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-04-16 09:28:41 -04:00
. require_equals ( true )
. long ( " reload " )
. value_name ( " CACHE_BLOCKLIST " )
2024-08-12 11:55:33 -04:00
. help (
2024-08-21 09:54:59 -04:00
cstr! ( " Reload source code cache (recompile TypeScript)
2024-08-12 11:55:33 -04:00
< p ( 245 ) > no value Reload everything
jsr :@ std / http / file - server , jsr :@ std / assert / assert - equals Reloads specific modules
npm : Reload all npm modules
npm :chalk Reload specific npm module < / > " ,
) )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::FilePath )
2023-03-26 00:06:18 -04:00
. value_parser ( reload_arg_validate )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn ca_file_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " cert " )
2021-04-16 09:28:41 -04:00
. long ( " cert " )
. value_name ( " FILE " )
. help ( " Load certificate authority from PEM encoded file " )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::FilePath )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn cached_only_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " cached-only " )
2021-04-16 09:28:41 -04:00
. long ( " cached-only " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2021-04-16 09:28:41 -04:00
. help ( " Require that remote dependencies are already cached " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2021-04-16 09:28:41 -04:00
}
2024-07-02 18:00:16 -04:00
fn frozen_lockfile_arg ( ) -> Arg {
Arg ::new ( " frozen " )
. long ( " frozen " )
. alias ( " frozen-lockfile " )
. value_parser ( value_parser! ( bool ) )
2024-08-12 11:55:33 -04:00
. value_name ( " BOOLEAN " )
2024-07-02 18:00:16 -04:00
. num_args ( 0 ..= 1 )
. require_equals ( true )
. default_missing_value ( " true " )
. help ( " Error out if lockfile is out of date " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2024-07-02 18:00:16 -04:00
}
2023-03-22 10:15:53 -04:00
/// Used for subcommands that operate on executable scripts only.
/// `deno fmt` has its own `--ext` arg because its possible values differ.
/// If --ext is not provided and the script doesn't have a file extension,
/// deno_graph::parse_module() defaults to js.
2023-03-26 00:06:18 -04:00
fn executable_ext_arg ( ) -> Arg {
2023-03-22 10:15:53 -04:00
Arg ::new ( " ext " )
. long ( " ext " )
. help ( " Set content type of the supplied file " )
2023-03-26 00:06:18 -04:00
. value_parser ( [ " ts " , " tsx " , " js " , " jsx " ] )
2023-03-22 10:15:53 -04:00
}
2023-03-26 00:06:18 -04:00
fn location_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " location " )
2021-04-16 09:28:41 -04:00
. long ( " location " )
. value_name ( " HREF " )
2023-03-26 00:06:18 -04:00
. value_parser ( | href : & str | -> Result < Url , String > {
2022-01-14 11:38:17 -05:00
let url = Url ::parse ( href ) ;
2021-04-16 09:28:41 -04:00
if url . is_err ( ) {
return Err ( " Failed to parse URL " . to_string ( ) ) ;
}
let mut url = url . unwrap ( ) ;
if ! [ " http " , " https " ] . contains ( & url . scheme ( ) ) {
return Err ( " Expected protocol \" http \" or \" https \" " . to_string ( ) ) ;
}
url . set_username ( " " ) . unwrap ( ) ;
url . set_password ( None ) . unwrap ( ) ;
2023-03-26 00:06:18 -04:00
Ok ( url )
2021-04-16 09:28:41 -04:00
} )
. help ( " Value of 'globalThis.location' used by some web APIs " )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::Url )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn enable_testing_features_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " enable-testing-features-do-not-use " )
2021-07-23 10:31:16 -04:00
. long ( " enable-testing-features-do-not-use " )
. help ( " INTERNAL: Enable internal features used during integration testing " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2022-01-14 11:38:17 -05:00
. hide ( true )
2021-07-23 10:31:16 -04:00
}
2023-11-10 12:41:24 -05:00
fn strace_ops_arg ( ) -> Arg {
Arg ::new ( " strace-ops " )
. long ( " strace-ops " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " OPS " )
. help ( " Trace low-level op calls " )
. hide ( true )
}
2023-03-26 00:06:18 -04:00
fn v8_flags_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " v8-flags " )
2021-04-16 09:28:41 -04:00
. long ( " v8-flags " )
2023-03-26 00:06:18 -04:00
. num_args ( .. )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-04-16 09:28:41 -04:00
. require_equals ( true )
2024-08-12 11:55:33 -04:00
. value_name ( " V8_FLAGS " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " To see a list of all available flags use --v8-flags=--help
< p ( 245 ) > Flags can also be set via the DENO_V8_FLAGS environment variable .
Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable < / > " ))
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn seed_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " seed " )
2021-04-16 09:28:41 -04:00
. long ( " seed " )
. value_name ( " NUMBER " )
2022-04-11 01:01:02 -04:00
. help ( " Set the random number generator seed " )
2023-03-26 00:06:18 -04:00
. value_parser ( value_parser! ( u64 ) )
2021-04-16 09:28:41 -04:00
}
2023-10-30 20:25:58 -04:00
fn hmr_arg ( takes_files : bool ) -> Arg {
let arg = Arg ::new ( " hmr " )
2024-08-11 18:10:55 -04:00
. long ( " watch-hmr " )
// NOTE(bartlomieju): compatibility with Deno pre-1.46
. alias ( " unstable-hmr " )
. help ( " Watch for file changes and hot replace modules " )
2024-08-18 18:39:53 -04:00
. conflicts_with ( " watch " )
. help_heading ( FILE_WATCHING_HEADING ) ;
2023-10-30 20:25:58 -04:00
if takes_files {
arg
. value_name ( " FILES " )
. num_args ( 0 .. )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2023-10-30 20:25:58 -04:00
. use_value_delimiter ( true )
. require_equals ( true )
2024-08-12 11:55:33 -04:00
. help (
2024-08-21 09:54:59 -04:00
cstr! (
2024-08-18 18:39:53 -04:00
" Watch for file changes and restart process automatically.
< p ( 245 ) > Local files from entry point module graph are watched by default .
Additional paths might be watched by passing them as arguments to this flag . < / > " ),
2023-10-30 20:25:58 -04:00
)
. value_hint ( ValueHint ::AnyPath )
} else {
2024-08-21 09:54:59 -04:00
arg . action ( ArgAction ::SetTrue ) . help ( cstr! (
2024-08-18 18:39:53 -04:00
" Watch for file changes and restart process automatically.
< p ( 245 ) > Only local files from entry point module graph are watched . < / > "
) )
2023-10-30 20:25:58 -04:00
}
}
2023-03-26 00:06:18 -04:00
fn watch_arg ( takes_files : bool ) -> Arg {
2024-08-18 18:39:53 -04:00
let arg = Arg ::new ( " watch " )
. long ( " watch " )
. help_heading ( FILE_WATCHING_HEADING ) ;
2021-12-15 16:04:43 -05:00
if takes_files {
arg
. value_name ( " FILES " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2022-03-27 21:57:56 -04:00
. use_value_delimiter ( true )
2021-12-15 16:04:43 -05:00
. require_equals ( true )
2024-08-12 11:55:33 -04:00
. help (
2024-08-21 09:54:59 -04:00
cstr! (
2022-06-26 18:28:45 -04:00
" Watch for file changes and restart process automatically.
2024-08-18 18:39:53 -04:00
< p ( 245 ) > Local files from entry point module graph are watched by default .
Additional paths might be watched by passing them as arguments to this flag . < / > " ),
2021-12-15 16:04:43 -05:00
)
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::AnyPath )
2021-12-15 16:04:43 -05:00
} else {
2024-08-21 09:54:59 -04:00
arg . action ( ArgAction ::SetTrue ) . help ( cstr! (
2023-03-27 12:28:41 -04:00
" Watch for file changes and restart process automatically.
2024-08-18 18:39:53 -04:00
< p ( 245 ) > Only local files from entry point module graph are watched . < / > "
) )
2021-12-15 16:04:43 -05:00
}
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn no_clear_screen_arg ( ) -> Arg {
2022-01-31 11:39:39 -05:00
Arg ::new ( " no-clear-screen " )
. requires ( " watch " )
. long ( " no-clear-screen " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2022-01-31 11:39:39 -05:00
. help ( " Do not clear terminal screen when under watch mode " )
2024-08-18 18:39:53 -04:00
. help_heading ( FILE_WATCHING_HEADING )
2022-01-31 11:39:39 -05:00
}
2024-04-17 10:19:55 -04:00
fn no_code_cache_arg ( ) -> Arg {
Arg ::new ( " no-code-cache " )
. long ( " no-code-cache " )
. help ( " Disable V8 code cache feature " )
. action ( ArgAction ::SetTrue )
}
2024-03-27 18:47:46 -04:00
fn watch_exclude_arg ( ) -> Arg {
Arg ::new ( " watch-exclude " )
. long ( " watch-exclude " )
. help ( " Exclude provided files/patterns from watch mode " )
. value_name ( " FILES " )
. num_args ( 0 .. )
. value_parser ( value_parser! ( String ) )
. use_value_delimiter ( true )
. require_equals ( true )
. value_hint ( ValueHint ::AnyPath )
2024-08-18 18:39:53 -04:00
. help_heading ( FILE_WATCHING_HEADING )
2024-03-27 18:47:46 -04:00
}
2023-03-26 00:06:18 -04:00
fn no_check_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " no-check " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2021-11-29 17:23:30 -05:00
. require_equals ( true )
. value_name ( " NO_CHECK_TYPE " )
2021-04-16 09:28:41 -04:00
. long ( " no-check " )
2024-08-21 09:54:59 -04:00
. help ( " Skip type-checking. If the value of \" remote \" is supplied, diagnostic errors from remote modules will be ignored " )
2024-08-18 18:39:53 -04:00
. help_heading ( TYPE_CHECKING_HEADING )
2021-04-16 09:28:41 -04:00
}
2023-04-12 21:42:28 -04:00
fn check_arg ( checks_local_by_default : bool ) -> Arg {
let arg = Arg ::new ( " check " )
2022-04-10 19:12:51 -04:00
. conflicts_with ( " no-check " )
. long ( " check " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2022-04-10 19:12:51 -04:00
. require_equals ( true )
2024-08-18 18:39:53 -04:00
. value_name ( " CHECK_TYPE " )
. help_heading ( TYPE_CHECKING_HEADING ) ;
2022-04-10 19:12:51 -04:00
2023-04-12 21:42:28 -04:00
if checks_local_by_default {
2024-08-12 11:55:33 -04:00
arg . help (
2024-08-21 09:54:59 -04:00
cstr! ( " Set type-checking behavior. This subcommand type-checks local modules by default, so adding --check is redundant
< p ( 245 ) > If the value of \ " all \" is supplied, remote modules will be included.
Alternatively , the ' deno check ' subcommand can be used < / > " ,
) )
2023-04-12 21:42:28 -04:00
} else {
2024-08-21 09:54:59 -04:00
arg . help ( cstr! (
" Enable type-checking. This subcommand does not type-check by default
< p ( 245 ) > If the value of \ " all \" is supplied, remote modules will be included.
Alternatively , the ' deno check ' subcommand can be used < / > "
) )
2023-04-12 21:42:28 -04:00
}
2022-04-10 19:12:51 -04:00
}
2023-03-26 00:06:18 -04:00
fn script_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " script_arg " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 .. )
. action ( ArgAction ::Append )
2021-04-16 09:28:41 -04:00
// NOTE: these defaults are provided
// so `deno run --v8-flags=--help` works
// without specifying file to run.
2023-03-26 00:06:18 -04:00
. default_value_ifs ( [
( " v8-flags " , " --help " , Some ( " _ " ) ) ,
( " v8-flags " , " -help " , Some ( " _ " ) ) ,
2021-04-16 09:28:41 -04:00
] )
. help ( " Script arg " )
. value_name ( " SCRIPT_ARG " )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::FilePath )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn lock_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " lock " )
2021-04-16 09:28:41 -04:00
. long ( " lock " )
. value_name ( " FILE " )
2024-08-12 11:55:33 -04:00
. default_missing_value ( " ./deno.lock " )
. help ( " Check the specified lock file. (If value is not provided, defaults to \" ./deno.lock \" ) " )
2023-03-26 00:06:18 -04:00
. num_args ( 0 ..= 1 )
2024-03-14 19:53:46 -04:00
. value_parser ( value_parser! ( String ) )
2022-03-14 14:41:35 -04:00
. value_hint ( ValueHint ::FilePath )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn no_lock_arg ( ) -> Arg {
2022-11-03 11:42:56 -04:00
Arg ::new ( " no-lock " )
. long ( " no-lock " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2024-08-12 11:55:33 -04:00
. help ( " Disable auto discovery of the lock file " )
2022-11-03 11:42:56 -04:00
. conflicts_with ( " lock " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2022-11-03 11:42:56 -04:00
}
2023-03-26 00:06:18 -04:00
fn config_arg ( ) -> Arg {
2022-06-28 15:47:51 -04:00
Arg ::new ( " config " )
. short ( 'c' )
. long ( " config " )
. value_name ( " FILE " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Configure different aspects of deno including TypeScript, linting, and code formatting
< p ( 245 ) > Typically the configuration file will be called ` deno . json ` or ` deno . jsonc ` and
2024-08-12 11:55:33 -04:00
automatically detected ; in that case this flag is not necessary .
2024-08-21 09:54:59 -04:00
Docs : https ://docs.deno.com/go/config</>"))
2022-06-28 15:47:51 -04:00
. value_hint ( ValueHint ::FilePath )
}
2023-03-26 00:06:18 -04:00
fn no_config_arg ( ) -> Arg {
2022-06-28 15:47:51 -04:00
Arg ::new ( " no-config " )
. long ( " no-config " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2024-08-21 09:54:59 -04:00
. help ( " Disable automatic loading of the configuration file " )
2022-06-28 15:47:51 -04:00
. conflicts_with ( " config " )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn no_remote_arg ( ) -> Arg {
2022-01-14 11:38:17 -05:00
Arg ::new ( " no-remote " )
2021-04-16 09:28:41 -04:00
. long ( " no-remote " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2021-04-16 09:28:41 -04:00
. help ( " Do not resolve remote modules " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn no_npm_arg ( ) -> Arg {
2022-09-07 09:33:51 -04:00
Arg ::new ( " no-npm " )
. long ( " no-npm " )
2023-03-26 00:06:18 -04:00
. action ( ArgAction ::SetTrue )
2022-09-07 09:33:51 -04:00
. help ( " Do not resolve npm modules " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2022-09-07 09:33:51 -04:00
}
2024-08-29 18:57:43 -04:00
fn node_modules_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-30 17:58:24 -04:00
let value = matches . remove_one ::< NodeModulesDirMode > ( " node-modules-dir " ) ;
if let Some ( mode ) = value {
flags . node_modules_dir = Some ( mode ) ;
2024-08-29 18:57:43 -04:00
}
}
2024-08-30 17:58:24 -04:00
fn node_modules_dir_arg ( ) -> Arg {
fn parse_node_modules_dir_mode (
s : & str ,
) -> Result < NodeModulesDirMode , String > {
match s {
" auto " | " true " = > Ok ( NodeModulesDirMode ::Auto ) ,
" manual " = > Ok ( NodeModulesDirMode ::Manual ) ,
" none " | " false " = > Ok ( NodeModulesDirMode ::None ) ,
_ = > Err ( format! (
" Invalid value '{}': expected \" auto \" , \" manual \" or \" none \" " ,
s
) ) ,
}
2024-08-29 18:57:43 -04:00
}
2024-08-30 17:58:24 -04:00
Arg ::new ( " node-modules-dir " )
. long ( " node-modules-dir " )
. num_args ( 0 ..= 1 )
. value_parser ( clap ::builder ::ValueParser ::new ( parse_node_modules_dir_mode ) )
. value_name ( " MODE " )
. require_equals ( true )
. help ( " Sets the node modules management mode for npm packages " )
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
2022-09-22 11:17:02 -04:00
}
2023-08-06 21:56:56 -04:00
fn vendor_arg ( ) -> Arg {
Arg ::new ( " vendor " )
. long ( " vendor " )
2023-08-01 20:49:09 -04:00
. num_args ( 0 ..= 1 )
. value_parser ( value_parser! ( bool ) )
. default_missing_value ( " true " )
. require_equals ( true )
2024-08-21 09:54:59 -04:00
. help ( " Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages " )
2024-08-18 18:39:53 -04:00
. help_heading ( DEPENDENCY_MANAGEMENT_HEADING )
}
fn unsafely_ignore_certificate_errors_arg ( ) -> Arg {
Arg ::new ( " unsafely-ignore-certificate-errors " )
. hide ( true )
. long ( " unsafely-ignore-certificate-errors " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " HOSTNAMES " )
. help ( " DANGER: Disables verification of TLS certificates " )
. value_parser ( flags_net ::validator )
2021-12-10 09:47:55 -05:00
}
2024-07-09 23:06:08 -04:00
fn allow_scripts_arg ( ) -> Arg {
Arg ::new ( " allow-scripts " )
. long ( " allow-scripts " )
. num_args ( 0 .. )
. use_value_delimiter ( true )
. require_equals ( true )
. value_name ( " PACKAGE " )
. value_parser ( parse_packages_allowed_scripts )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Allow running npm lifecycle scripts for the given packages
< p ( 245 ) > Note : Scripts will only be executed when using a node_modules directory ( ` - - node - modules - dir ` ) < / > " ))
2024-07-09 23:06:08 -04:00
}
2024-08-18 18:39:53 -04:00
enum UnstableArgsConfig {
// for backwards-compatability
None ,
ResolutionOnly ,
ResolutionAndRuntime ,
}
struct UnstableArgsIter {
idx : usize ,
cfg : UnstableArgsConfig ,
}
impl Iterator for UnstableArgsIter {
type Item = Arg ;
fn next ( & mut self ) -> Option < Self ::Item > {
let arg = if self . idx = = 0 {
Arg ::new ( " unstable " )
. long ( " unstable " )
2024-08-21 09:54:59 -04:00
. help ( cstr! ( " Enable all unstable features and APIs. Instead of using this flag, consider enabling individual unstable features
< p ( 245 ) > To view the list of individual unstable feature flags , run this command again with - - help = unstable < / > " ))
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. hide ( matches! ( self . cfg , UnstableArgsConfig ::None ) )
} else if self . idx = = 1 {
Arg ::new ( " unstable-bare-node-builtins " )
. long ( " unstable-bare-node-builtins " )
. help ( " Enable unstable bare node builtins feature " )
. env ( " DENO_UNSTABLE_BARE_NODE_BUILTINS " )
. value_parser ( FalseyValueParser ::new ( ) )
. action ( ArgAction ::SetTrue )
. hide ( true )
. long_help ( match self . cfg {
UnstableArgsConfig ::None = > None ,
UnstableArgsConfig ::ResolutionOnly
| UnstableArgsConfig ::ResolutionAndRuntime = > Some ( " true " ) ,
} )
. help_heading ( UNSTABLE_HEADING )
} else if self . idx = = 2 {
Arg ::new ( " unstable-byonm " )
. long ( " unstable-byonm " )
. value_parser ( FalseyValueParser ::new ( ) )
. action ( ArgAction ::SetTrue )
. hide ( true )
. help_heading ( UNSTABLE_HEADING )
} else if self . idx = = 3 {
Arg ::new ( " unstable-sloppy-imports " )
. long ( " unstable-sloppy-imports " )
2024-08-21 09:54:59 -04:00
. help ( " Enable unstable resolving of specifiers by extension probing, .js to .ts, and directory probing " )
2024-08-18 18:39:53 -04:00
. env ( " DENO_UNSTABLE_SLOPPY_IMPORTS " )
. value_parser ( FalseyValueParser ::new ( ) )
. action ( ArgAction ::SetTrue )
. hide ( true )
. long_help ( match self . cfg {
UnstableArgsConfig ::None = > None ,
UnstableArgsConfig ::ResolutionOnly | UnstableArgsConfig ::ResolutionAndRuntime = > Some ( " true " )
} )
. help_heading ( UNSTABLE_HEADING )
} else if self . idx > 3 {
2024-08-27 07:45:27 -04:00
let granular_flag = crate ::UNSTABLE_GRANULAR_FLAGS . get ( self . idx - 4 ) ? ;
Arg ::new ( format! ( " unstable- {} " , granular_flag . name ) )
. long ( format! ( " unstable- {} " , granular_flag . name ) )
. help ( granular_flag . help_text )
2024-08-18 18:39:53 -04:00
. action ( ArgAction ::SetTrue )
. hide ( true )
. help_heading ( UNSTABLE_HEADING )
// we don't render long help, so using it here as a sort of metadata
2024-08-27 07:45:27 -04:00
. long_help ( if granular_flag . show_in_help {
match self . cfg {
UnstableArgsConfig ::None | UnstableArgsConfig ::ResolutionOnly = > {
None
}
UnstableArgsConfig ::ResolutionAndRuntime = > Some ( " true " ) ,
}
} else {
None
2024-08-18 18:39:53 -04:00
} )
} else {
return None ;
} ;
self . idx + = 1 ;
Some ( arg . display_order ( self . idx + 1000 ) )
}
}
fn unstable_args ( cfg : UnstableArgsConfig ) -> impl IntoIterator < Item = Arg > {
UnstableArgsIter { idx : 0 , cfg }
}
2024-07-09 23:06:08 -04:00
fn allow_scripts_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
let Some ( parts ) = matches . remove_many ::< String > ( " allow-scripts " ) else {
return ;
} ;
if parts . len ( ) = = 0 {
flags . allow_scripts = PackagesAllowedScripts ::All ;
} else {
flags . allow_scripts = PackagesAllowedScripts ::Some ( parts . collect ( ) ) ;
}
}
2024-02-29 14:12:04 -05:00
fn add_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-05-08 15:34:46 -04:00
flags . subcommand = DenoSubcommand ::Add ( add_parse_inner ( matches , None ) ) ;
}
fn add_parse_inner (
matches : & mut ArgMatches ,
packages : Option < clap ::parser ::Values < String > > ,
) -> AddFlags {
let packages = packages
. unwrap_or_else ( | | matches . remove_many ::< String > ( " packages " ) . unwrap ( ) )
. collect ( ) ;
AddFlags { packages }
2024-02-29 14:12:04 -05:00
}
2024-08-12 16:17:25 -04:00
fn remove_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . subcommand = DenoSubcommand ::Remove ( RemoveFlags {
packages : matches . remove_many ::< String > ( " packages " ) . unwrap ( ) . collect ( ) ,
} ) ;
}
2023-03-26 00:06:18 -04:00
fn bench_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::Local ;
2022-03-11 17:07:02 -05:00
runtime_args_parse ( flags , matches , true , false ) ;
// NOTE: `deno bench` always uses `--no-prompt`, tests shouldn't ever do
// interactive prompts, unless done by user code
2024-05-06 19:21:58 -04:00
flags . permissions . no_prompt = true ;
2022-03-11 17:07:02 -05:00
2023-03-26 00:06:18 -04:00
let json = matches . get_flag ( " json " ) ;
2023-02-12 12:40:45 -05:00
2024-01-15 19:15:39 -05:00
let ignore = match matches . remove_many ::< String > ( " ignore " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2022-03-11 17:07:02 -05:00
None = > vec! [ ] ,
} ;
2023-03-26 00:06:18 -04:00
let filter = matches . remove_one ::< String > ( " filter " ) ;
2022-03-11 17:07:02 -05:00
2023-03-26 00:06:18 -04:00
if matches . contains_id ( " script_arg " ) {
flags
. argv
. extend ( matches . remove_many ::< String > ( " script_arg " ) . unwrap ( ) ) ;
2022-03-11 17:07:02 -05:00
}
2024-01-15 19:15:39 -05:00
let include = if let Some ( files ) = matches . remove_many ::< String > ( " files " ) {
2023-03-26 00:06:18 -04:00
files . collect ( )
2022-03-11 17:07:02 -05:00
} else {
2023-01-07 15:22:09 -05:00
Vec ::new ( )
2022-03-11 17:07:02 -05:00
} ;
2023-03-26 10:55:58 -04:00
let no_run = matches . get_flag ( " no-run " ) ;
2022-03-11 17:07:02 -05:00
flags . subcommand = DenoSubcommand ::Bench ( BenchFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags { include , ignore } ,
2022-03-11 17:07:02 -05:00
filter ,
2023-02-12 12:40:45 -05:00
json ,
2023-03-26 10:55:58 -04:00
no_run ,
2023-06-15 13:09:37 -04:00
watch : watch_arg_parse ( matches ) ,
2022-03-11 17:07:02 -05:00
} ) ;
}
2024-09-02 11:27:37 -04:00
fn bundle_parse ( flags : & mut Flags , _matches : & mut ArgMatches ) {
flags . subcommand = DenoSubcommand ::Bundle ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn cache_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2021-04-16 09:28:41 -04:00
compile_args_parse ( flags , matches ) ;
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionOnly ) ;
2024-07-02 18:00:16 -04:00
frozen_lockfile_arg_parse ( flags , matches ) ;
2024-07-09 23:06:08 -04:00
allow_scripts_arg_parse ( flags , matches ) ;
2023-03-26 00:06:18 -04:00
let files = matches . remove_many ::< String > ( " file " ) . unwrap ( ) . collect ( ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Cache ( CacheFlags { files } ) ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn check_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::Local ;
2023-03-13 17:04:00 -04:00
compile_args_without_check_parse ( flags , matches ) ;
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionAndRuntime ) ;
2023-03-26 00:06:18 -04:00
let files = matches . remove_many ::< String > ( " file " ) . unwrap ( ) . collect ( ) ;
if matches . get_flag ( " all " ) | | matches . get_flag ( " remote " ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::All ;
}
flags . subcommand = DenoSubcommand ::Check ( CheckFlags { files } ) ;
2022-04-10 19:12:51 -04:00
}
2024-08-08 09:22:18 -04:00
fn clean_parse ( flags : & mut Flags , _matches : & mut ArgMatches ) {
flags . subcommand = DenoSubcommand ::Clean ;
}
2023-03-26 00:06:18 -04:00
fn compile_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::Local ;
2021-04-16 09:28:41 -04:00
runtime_args_parse ( flags , matches , true , false ) ;
2023-03-26 00:06:18 -04:00
let mut script = matches . remove_many ::< String > ( " script_arg " ) . unwrap ( ) ;
let source_file = script . next ( ) . unwrap ( ) ;
let args = script . collect ( ) ;
2024-03-14 19:53:46 -04:00
let output = matches . remove_one ::< String > ( " output " ) ;
2023-03-26 00:06:18 -04:00
let target = matches . remove_one ::< String > ( " target " ) ;
2024-08-15 00:42:23 -04:00
let icon = matches . remove_one ::< String > ( " icon " ) ;
2023-07-28 11:46:26 -04:00
let no_terminal = matches . get_flag ( " no-terminal " ) ;
2023-03-26 00:06:18 -04:00
let include = match matches . remove_many ::< String > ( " include " ) {
Some ( f ) = > f . collect ( ) ,
2023-03-18 19:43:07 -04:00
None = > vec! [ ] ,
} ;
2023-03-22 10:15:53 -04:00
ext_arg_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Compile ( CompileFlags {
2021-04-16 09:28:41 -04:00
source_file ,
output ,
args ,
target ,
2023-07-28 11:46:26 -04:00
no_terminal ,
2024-08-15 00:42:23 -04:00
icon ,
2023-03-18 19:43:07 -04:00
include ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-04-16 09:28:41 -04:00
}
2022-01-14 11:38:17 -05:00
fn completions_parse (
flags : & mut Flags ,
2023-03-26 00:06:18 -04:00
matches : & mut ArgMatches ,
mut app : Command ,
2022-01-14 11:38:17 -05:00
) {
use clap_complete ::generate ;
2023-01-14 23:18:58 -05:00
use clap_complete ::shells ::Bash ;
use clap_complete ::shells ::Fish ;
use clap_complete ::shells ::PowerShell ;
use clap_complete ::shells ::Zsh ;
2022-01-14 11:38:17 -05:00
use clap_complete_fig ::Fig ;
2021-04-16 09:28:41 -04:00
let mut buf : Vec < u8 > = vec! [ ] ;
2022-01-14 11:38:17 -05:00
let name = " deno " ;
2023-03-26 00:06:18 -04:00
match matches . get_one ::< String > ( " shell " ) . unwrap ( ) . as_str ( ) {
2022-01-14 11:38:17 -05:00
" bash " = > generate ( Bash , & mut app , name , & mut buf ) ,
" fish " = > generate ( Fish , & mut app , name , & mut buf ) ,
" powershell " = > generate ( PowerShell , & mut app , name , & mut buf ) ,
" zsh " = > generate ( Zsh , & mut app , name , & mut buf ) ,
" fig " = > generate ( Fig , & mut app , name , & mut buf ) ,
_ = > unreachable! ( ) ,
}
2021-04-16 09:28:41 -04:00
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Completions ( CompletionsFlags {
2021-04-16 09:28:41 -04:00
buf : buf . into_boxed_slice ( ) ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn coverage_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-01-15 19:15:39 -05:00
let files = match matches . remove_many ::< String > ( " files " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2024-01-15 19:15:39 -05:00
None = > vec! [ " coverage " . to_string ( ) ] , // default
2021-04-16 09:28:41 -04:00
} ;
2024-01-15 19:15:39 -05:00
let ignore = match matches . remove_many ::< String > ( " ignore " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2023-03-26 00:06:18 -04:00
let include = match matches . remove_many ::< String > ( " include " ) {
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2023-03-26 00:06:18 -04:00
let exclude = match matches . remove_many ::< String > ( " exclude " ) {
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2023-12-08 02:54:52 -05:00
let r#type = if matches . get_flag ( " lcov " ) {
CoverageType ::Lcov
} else if matches . get_flag ( " html " ) {
CoverageType ::Html
2023-12-12 06:53:41 -05:00
} else if matches . get_flag ( " detailed " ) {
CoverageType ::Detailed
2023-12-11 22:42:57 -05:00
} else {
CoverageType ::Summary
2023-12-08 02:54:52 -05:00
} ;
2024-03-14 19:53:46 -04:00
let output = matches . remove_one ::< String > ( " output " ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Coverage ( CoverageFlags {
2023-01-13 16:56:29 -05:00
files : FileFlags {
include : files ,
ignore ,
} ,
2022-02-15 10:33:21 -05:00
output ,
2021-04-16 09:28:41 -04:00
include ,
exclude ,
2023-12-08 02:54:52 -05:00
r#type ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn doc_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionOnly ) ;
2021-04-16 09:28:41 -04:00
import_map_arg_parse ( flags , matches ) ;
reload_arg_parse ( flags , matches ) ;
2023-03-13 17:04:00 -04:00
lock_arg_parse ( flags , matches ) ;
no_lock_arg_parse ( flags , matches ) ;
no_npm_arg_parse ( flags , matches ) ;
no_remote_arg_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
2023-10-30 18:58:57 -04:00
let source_files_val = matches . remove_many ::< String > ( " source_file " ) ;
let source_files = if let Some ( val ) = source_files_val {
let vals : Vec < String > = val . collect ( ) ;
if vals . len ( ) = = 1 {
if vals [ 0 ] = = " --builtin " {
2023-01-14 12:39:56 -05:00
DocSourceFileFlag ::Builtin
} else {
2023-10-30 18:58:57 -04:00
DocSourceFileFlag ::Paths ( vec! [ vals [ 0 ] . to_string ( ) ] )
2023-01-14 12:39:56 -05:00
}
2023-10-30 18:58:57 -04:00
} else {
DocSourceFileFlag ::Paths (
vals . into_iter ( ) . filter ( | v | v ! = " --builtin " ) . collect ( ) ,
)
}
} else {
DocSourceFileFlag ::Builtin
} ;
2023-03-26 00:06:18 -04:00
let private = matches . get_flag ( " private " ) ;
2023-10-31 18:19:42 -04:00
let lint = matches . get_flag ( " lint " ) ;
2023-03-26 00:06:18 -04:00
let json = matches . get_flag ( " json " ) ;
let filter = matches . remove_one ::< String > ( " filter " ) ;
2023-11-01 11:25:05 -04:00
let html = if matches . get_flag ( " html " ) {
2024-04-24 16:34:21 -04:00
let name = matches . remove_one ::< String > ( " name " ) ;
2024-06-28 08:03:51 -04:00
let category_docs_path = matches . remove_one ::< String > ( " category-docs " ) ;
let symbol_redirect_map_path =
matches . remove_one ::< String > ( " symbol-redirect-map " ) ;
let strip_trailing_html = matches . get_flag ( " strip-trailing-html " ) ;
let default_symbol_map_path =
matches . remove_one ::< String > ( " default-symbol-map " ) ;
2023-11-01 11:25:05 -04:00
let output = matches
2024-03-14 19:53:46 -04:00
. remove_one ::< String > ( " output " )
. unwrap_or ( String ::from ( " ./docs/ " ) ) ;
2024-06-28 08:03:51 -04:00
Some ( DocHtmlFlag {
name ,
category_docs_path ,
symbol_redirect_map_path ,
default_symbol_map_path ,
strip_trailing_html ,
output ,
} )
2023-11-01 11:25:05 -04:00
} else {
None
} ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Doc ( DocFlags {
2023-10-30 18:58:57 -04:00
source_files ,
2021-04-16 09:28:41 -04:00
json ,
2023-10-31 18:19:42 -04:00
lint ,
2023-11-01 11:25:05 -04:00
html ,
2021-04-16 09:28:41 -04:00
filter ,
private ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn eval_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2021-04-16 09:28:41 -04:00
runtime_args_parse ( flags , matches , false , true ) ;
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionAndRuntime ) ;
2024-03-13 12:07:24 -04:00
flags . allow_all ( ) ;
2023-03-22 10:15:53 -04:00
ext_arg_parse ( flags , matches ) ;
2023-03-26 00:06:18 -04:00
let print = matches . get_flag ( " print " ) ;
let mut code_args = matches . remove_many ::< String > ( " code_arg " ) . unwrap ( ) ;
let code = code_args . next ( ) . unwrap ( ) ;
flags . argv . extend ( code_args ) ;
2023-03-22 10:15:53 -04:00
flags . subcommand = DenoSubcommand ::Eval ( EvalFlags { print , code } ) ;
2021-04-16 09:28:41 -04:00
}
2023-03-26 00:06:18 -04:00
fn fmt_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-05-13 11:40:50 -04:00
config_args_parse ( flags , matches ) ;
2023-03-22 10:15:53 -04:00
ext_arg_parse ( flags , matches ) ;
2022-01-31 11:39:39 -05:00
2024-01-15 19:15:39 -05:00
let include = match matches . remove_many ::< String > ( " files " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2024-01-15 19:15:39 -05:00
let ignore = match matches . remove_many ::< String > ( " ignore " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2019-04-29 19:43:06 -04:00
2023-03-26 00:06:18 -04:00
let use_tabs = matches . remove_one ::< bool > ( " use-tabs " ) ;
let line_width = matches . remove_one ::< NonZeroU32 > ( " line-width " ) ;
let indent_width = matches . remove_one ::< NonZeroU8 > ( " indent-width " ) ;
let single_quote = matches . remove_one ::< bool > ( " single-quote " ) ;
let prose_wrap = matches . remove_one ::< String > ( " prose-wrap " ) ;
let no_semicolons = matches . remove_one ::< bool > ( " no-semicolons " ) ;
2024-08-09 12:52:23 -04:00
let unstable_css = matches . get_flag ( " unstable-css " ) ;
2024-08-14 16:58:48 -04:00
let unstable_html = matches . get_flag ( " unstable-html " ) ;
let unstable_component = matches . get_flag ( " unstable-component " ) ;
2024-08-02 09:52:48 -04:00
let unstable_yaml = matches . get_flag ( " unstable-yaml " ) ;
2021-09-13 16:06:45 -04:00
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Fmt ( FmtFlags {
2023-03-26 00:06:18 -04:00
check : matches . get_flag ( " check " ) ,
2023-01-07 15:22:09 -05:00
files : FileFlags { include , ignore } ,
2021-09-13 16:06:45 -04:00
use_tabs ,
line_width ,
indent_width ,
single_quote ,
prose_wrap ,
2023-01-25 15:06:00 -05:00
no_semicolons ,
2023-06-15 13:09:37 -04:00
watch : watch_arg_parse ( matches ) ,
2024-08-09 12:52:23 -04:00
unstable_css ,
2024-08-14 16:58:48 -04:00
unstable_html ,
unstable_component ,
2024-08-02 09:52:48 -04:00
unstable_yaml ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-04-16 09:28:41 -04:00
}
2019-07-27 05:20:40 -04:00
2023-03-26 00:06:18 -04:00
fn init_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-08-19 19:37:05 -04:00
flags . subcommand = DenoSubcommand ::Init ( InitFlags {
2023-03-26 00:06:18 -04:00
dir : matches . remove_one ::< String > ( " dir " ) ,
2024-07-09 21:13:34 -04:00
lib : matches . get_flag ( " lib " ) ,
2024-08-08 12:54:39 -04:00
serve : matches . get_flag ( " serve " ) ,
2022-08-19 19:37:05 -04:00
} ) ;
}
2023-03-26 00:06:18 -04:00
fn info_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionOnly ) ;
2021-04-16 09:28:41 -04:00
reload_arg_parse ( flags , matches ) ;
2022-06-13 14:09:04 -04:00
config_args_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
import_map_arg_parse ( flags , matches ) ;
2021-05-27 01:23:12 -04:00
location_arg_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
ca_file_arg_parse ( flags , matches ) ;
2024-08-18 18:39:53 -04:00
unsafely_ignore_certificate_errors_parse ( flags , matches ) ;
2023-08-06 21:56:56 -04:00
node_modules_and_vendor_dir_arg_parse ( flags , matches ) ;
2024-02-19 07:02:40 -05:00
lock_args_parse ( flags , matches ) ;
2023-03-13 17:04:00 -04:00
no_remote_arg_parse ( flags , matches ) ;
no_npm_arg_parse ( flags , matches ) ;
2023-03-26 00:06:18 -04:00
let json = matches . get_flag ( " json " ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Info ( InfoFlags {
2023-03-26 00:06:18 -04:00
file : matches . remove_one ::< String > ( " file " ) ,
2021-04-16 09:28:41 -04:00
json ,
2021-09-03 19:33:35 -04:00
} ) ;
2019-11-26 11:06:32 -05:00
}
2019-05-16 10:11:35 -04:00
2023-03-26 00:06:18 -04:00
fn install_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2021-04-16 09:28:41 -04:00
runtime_args_parse ( flags , matches , true , true ) ;
2024-03-27 18:45:57 -04:00
let global = matches . get_flag ( " global " ) ;
2024-08-30 17:58:24 -04:00
if global {
2024-05-08 15:34:46 -04:00
let root = matches . remove_one ::< String > ( " root " ) ;
let force = matches . get_flag ( " force " ) ;
let name = matches . remove_one ::< String > ( " name " ) ;
let mut cmd_values =
matches . remove_many ::< String > ( " cmd " ) . unwrap_or_default ( ) ;
let module_url = cmd_values . next ( ) . unwrap ( ) ;
let args = cmd_values . collect ( ) ;
flags . subcommand = DenoSubcommand ::Install ( InstallFlags {
// TODO(bartlomieju): remove for 2.0
global ,
kind : InstallKind ::Global ( InstallFlagsGlobal {
name ,
module_url ,
args ,
root ,
force ,
} ) ,
} ) ;
} else {
let local_flags = matches
. remove_many ( " cmd " )
. map ( | packages | add_parse_inner ( matches , Some ( packages ) ) ) ;
2024-07-09 23:06:08 -04:00
allow_scripts_arg_parse ( flags , matches ) ;
2024-05-08 15:34:46 -04:00
flags . subcommand = DenoSubcommand ::Install ( InstallFlags {
global ,
kind : InstallKind ::Local ( local_flags ) ,
} )
}
2020-01-08 14:59:53 -05:00
}
2024-08-12 11:55:33 -04:00
fn json_reference_parse (
flags : & mut Flags ,
_matches : & mut ArgMatches ,
mut app : Command ,
) {
use deno_core ::serde_json ::json ;
app . build ( ) ;
fn serialize_command (
command : & mut Command ,
top_level : bool ,
) -> deno_core ::serde_json ::Value {
let args = command
. get_arguments ( )
. filter ( | arg | {
! arg . is_hide_set ( )
& & if top_level {
true
} else {
! arg . is_global_set ( )
}
} )
. map ( | arg | {
let name = arg . get_id ( ) . as_str ( ) ;
let short = arg . get_short ( ) ;
let long = arg . get_long ( ) ;
let aliases = arg . get_visible_aliases ( ) ;
let required = arg . is_required_set ( ) ;
let help = arg . get_help ( ) . map ( | help | help . to_string ( ) ) ;
let usage = arg . to_string ( ) ;
json! ( {
" name " : name ,
" short " : short ,
" long " : long ,
" aliases " : aliases ,
" required " : required ,
" help " : help ,
" usage " : usage ,
} )
} )
. collect ::< Vec < _ > > ( ) ;
let name = command . get_name ( ) . to_string ( ) ;
let about = command . get_about ( ) . map ( | about | about . to_string ( ) ) ;
let visible_aliases = command
. get_visible_aliases ( )
. map ( | s | s . to_string ( ) )
. collect ::< Vec < _ > > ( ) ;
let usage = command . render_usage ( ) . to_string ( ) ;
let subcommands = command
. get_subcommands_mut ( )
. map ( | command | serialize_command ( command , false ) )
. collect ::< Vec < _ > > ( ) ;
json! ( {
" name " : name ,
" about " : about ,
" visible_aliases " : visible_aliases ,
" args " : args ,
" subcommands " : subcommands ,
" usage " : usage ,
} )
}
flags . subcommand = DenoSubcommand ::JSONReference ( JSONReferenceFlags {
json : serialize_command ( & mut app , true ) ,
} )
}
2023-09-15 20:42:09 -04:00
fn jupyter_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-03-14 19:53:46 -04:00
let conn_file = matches . remove_one ::< String > ( " conn " ) ;
2023-09-15 20:42:09 -04:00
let kernel = matches . get_flag ( " kernel " ) ;
let install = matches . get_flag ( " install " ) ;
flags . subcommand = DenoSubcommand ::Jupyter ( JupyterFlags {
install ,
kernel ,
conn_file ,
} ) ;
}
2023-03-26 00:06:18 -04:00
fn uninstall_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2023-11-13 09:44:01 -05:00
let root = matches . remove_one ::< String > ( " root " ) ;
2024-03-27 18:45:57 -04:00
let global = matches . get_flag ( " global " ) ;
2023-03-26 00:06:18 -04:00
let name = matches . remove_one ::< String > ( " name " ) . unwrap ( ) ;
2024-04-04 10:40:54 -04:00
flags . subcommand = DenoSubcommand ::Uninstall ( UninstallFlags {
// TODO(bartlomieju): remove once `deno uninstall` supports both local and
// global installs
global ,
kind : UninstallKind ::Global ( UninstallFlagsGlobal { name , root } ) ,
} ) ;
2021-09-30 11:38:07 -04:00
}
2023-03-26 00:06:18 -04:00
fn lsp_parse ( flags : & mut Flags , _matches : & mut ArgMatches ) {
2021-06-22 21:48:01 -04:00
flags . subcommand = DenoSubcommand ::Lsp ;
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2023-03-26 00:06:18 -04:00
fn lint_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionOnly ) ;
2022-05-13 11:40:50 -04:00
config_args_parse ( flags , matches ) ;
2024-01-15 19:15:39 -05:00
let files = match matches . remove_many ::< String > ( " files " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2024-01-15 19:15:39 -05:00
let ignore = match matches . remove_many ::< String > ( " ignore " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-04-16 09:28:41 -04:00
None = > vec! [ ] ,
} ;
2024-03-21 17:18:59 -04:00
let fix = matches . get_flag ( " fix " ) ;
2023-03-26 00:06:18 -04:00
let rules = matches . get_flag ( " rules " ) ;
2021-11-04 11:12:12 -04:00
let maybe_rules_tags = matches
2023-03-26 00:06:18 -04:00
. remove_many ::< String > ( " rules-tags " )
. map ( | f | f . collect ( ) ) ;
2021-11-04 11:12:12 -04:00
let maybe_rules_include = matches
2023-03-26 00:06:18 -04:00
. remove_many ::< String > ( " rules-include " )
. map ( | f | f . collect ( ) ) ;
2021-11-04 11:12:12 -04:00
let maybe_rules_exclude = matches
2023-03-26 00:06:18 -04:00
. remove_many ::< String > ( " rules-exclude " )
. map ( | f | f . collect ( ) ) ;
2021-11-04 11:12:12 -04:00
2023-03-26 00:06:18 -04:00
let json = matches . get_flag ( " json " ) ;
let compact = matches . get_flag ( " compact " ) ;
2024-08-19 16:42:13 -04:00
let ext = matches . remove_one ::< String > ( " ext " ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : files ,
ignore ,
} ,
2024-03-21 17:18:59 -04:00
fix ,
2021-04-16 09:28:41 -04:00
rules ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags ,
maybe_rules_include ,
maybe_rules_exclude ,
2021-04-16 09:28:41 -04:00
json ,
2022-09-28 12:47:48 -04:00
compact ,
2023-06-15 13:09:37 -04:00
watch : watch_arg_parse ( matches ) ,
2024-08-19 16:42:13 -04:00
ext ,
2021-09-03 19:33:35 -04:00
} ) ;
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2023-03-26 00:06:18 -04:00
fn repl_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-12-07 14:21:18 -05:00
runtime_args_parse ( flags , matches , true , true ) ;
2022-01-14 11:38:17 -05:00
unsafely_ignore_certificate_errors_parse ( flags , matches ) ;
2022-04-20 08:16:37 -04:00
2023-03-26 00:06:18 -04:00
let eval_files = matches
. remove_many ::< String > ( " eval-file " )
. map ( | values | values . collect ( ) ) ;
2022-04-20 08:16:37 -04:00
2022-01-14 11:38:17 -05:00
handle_repl_flags (
flags ,
ReplFlags {
2022-04-20 08:16:37 -04:00
eval_files ,
2023-03-26 00:06:18 -04:00
eval : matches . remove_one ::< String > ( " eval " ) ,
2022-12-07 14:21:18 -05:00
is_default_command : false ,
2022-01-14 11:38:17 -05:00
} ,
) ;
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2023-08-12 22:04:17 -04:00
fn run_parse (
flags : & mut Flags ,
matches : & mut ArgMatches ,
2024-08-21 09:54:59 -04:00
app : Command ,
2024-08-12 11:55:33 -04:00
bare : bool ,
2023-08-12 22:04:17 -04:00
) -> clap ::error ::Result < ( ) > {
2021-04-16 09:28:41 -04:00
runtime_args_parse ( flags , matches , true , true ) ;
2024-08-21 09:54:59 -04:00
ext_arg_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
2024-04-17 10:19:55 -04:00
flags . code_cache_enabled = ! matches . get_flag ( " no-code-cache " ) ;
2024-08-21 09:54:59 -04:00
if let Some ( mut script_arg ) = matches . remove_many ::< String > ( " script_arg " ) {
let script = script_arg . next ( ) . unwrap ( ) ;
flags . argv . extend ( script_arg ) ;
flags . subcommand = DenoSubcommand ::Run ( RunFlags {
script ,
watch : watch_arg_parse_with_paths ( matches ) ,
bare ,
} ) ;
} else if bare {
return Err ( app . override_usage ( " deno [OPTIONS] [COMMAND] [SCRIPT_ARG]... " ) . error (
clap ::error ::ErrorKind ::MissingRequiredArgument ,
" [SCRIPT_ARG] may only be omitted with --v8-flags=--help, else to use the repl with arguments, please use the `deno repl` subcommand " ,
) ) ;
} else {
flags . subcommand = DenoSubcommand ::Task ( TaskFlags {
cwd : None ,
task : None ,
is_run : true ,
} ) ;
}
2023-08-12 22:04:17 -04:00
Ok ( ( ) )
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2024-04-24 15:45:49 -04:00
fn serve_parse (
flags : & mut Flags ,
matches : & mut ArgMatches ,
app : Command ,
) -> clap ::error ::Result < ( ) > {
// deno serve implies --allow-net=host:port
2024-05-17 01:38:50 -04:00
let port = matches . remove_one ::< u16 > ( " port " ) . unwrap_or ( 8000 ) ;
2024-04-24 15:45:49 -04:00
let host = matches
. remove_one ::< String > ( " host " )
. unwrap_or_else ( | | " 0.0.0.0 " . to_owned ( ) ) ;
2024-09-02 11:26:42 -04:00
let worker_count = parallel_arg_parse ( matches ) . map ( | v | v . get ( ) ) ;
2024-08-14 18:26:21 -04:00
2024-04-24 15:45:49 -04:00
runtime_args_parse ( flags , matches , true , true ) ;
// If the user didn't pass --allow-net, add this port to the network
// allowlist. If the host is 0.0.0.0, we add :{port} and allow the same network perms
// as if it was passed to --allow-net directly.
let allowed = flags_net ::parse ( vec! [ if host = = " 0.0.0.0 " {
format! ( " : {port} " )
} else {
format! ( " {host} : {port} " )
} ] ) ? ;
2024-05-06 19:21:58 -04:00
match & mut flags . permissions . allow_net {
None = > flags . permissions . allow_net = Some ( allowed ) ,
2024-04-24 15:45:49 -04:00
Some ( v ) = > {
if ! v . is_empty ( ) {
v . extend ( allowed ) ;
}
}
}
flags . code_cache_enabled = ! matches . get_flag ( " no-code-cache " ) ;
let mut script_arg =
matches . remove_many ::< String > ( " script_arg " ) . ok_or_else ( | | {
let mut app = app ;
let subcommand = & mut app . find_subcommand_mut ( " serve " ) . unwrap ( ) ;
subcommand . error (
clap ::error ::ErrorKind ::MissingRequiredArgument ,
" [SCRIPT_ARG] may only be omitted with --v8-flags=--help " ,
)
} ) ? ;
let script = script_arg . next ( ) . unwrap ( ) ;
flags . argv . extend ( script_arg ) ;
ext_arg_parse ( flags , matches ) ;
flags . subcommand = DenoSubcommand ::Serve ( ServeFlags {
script ,
watch : watch_arg_parse_with_paths ( matches ) ,
port ,
host ,
2024-08-14 18:26:21 -04:00
worker_count ,
2024-04-24 15:45:49 -04:00
} ) ;
Ok ( ( ) )
}
2023-03-26 00:06:18 -04:00
fn task_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . config_flag = matches
. remove_one ::< String > ( " config " )
2023-04-26 13:07:15 -04:00
. map ( ConfigFlag ::Path )
. unwrap_or ( ConfigFlag ::Discover ) ;
2022-03-10 20:56:14 -05:00
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionAndRuntime ) ;
2022-06-08 17:30:16 -04:00
let mut task_flags = TaskFlags {
2023-03-26 00:06:18 -04:00
cwd : matches . remove_one ::< String > ( " cwd " ) ,
2023-02-22 22:45:35 -05:00
task : None ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-06-08 17:30:16 -04:00
} ;
2023-03-26 00:06:18 -04:00
if let Some ( ( task , mut matches ) ) = matches . remove_subcommand ( ) {
task_flags . task = Some ( task ) ;
2022-03-10 20:56:14 -05:00
2023-03-26 00:06:18 -04:00
flags . argv . extend (
matches
. remove_many ::< std ::ffi ::OsString > ( " " )
. into_iter ( )
. flatten ( )
. filter_map ( | arg | arg . into_string ( ) . ok ( ) ) ,
) ;
2022-03-10 20:56:14 -05:00
}
2022-06-08 17:30:16 -04:00
flags . subcommand = DenoSubcommand ::Task ( task_flags ) ;
2022-03-10 20:56:14 -05:00
}
2024-09-02 11:26:42 -04:00
fn parallel_arg_parse ( matches : & mut ArgMatches ) -> Option < NonZeroUsize > {
2024-08-14 18:26:21 -04:00
if matches . get_flag ( " parallel " ) {
if let Ok ( value ) = env ::var ( " DENO_JOBS " ) {
value . parse ::< NonZeroUsize > ( ) . ok ( )
} else {
std ::thread ::available_parallelism ( ) . ok ( )
}
} else {
None
}
}
2023-03-26 00:06:18 -04:00
fn test_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::Local ;
2021-04-16 09:28:41 -04:00
runtime_args_parse ( flags , matches , true , true ) ;
2022-02-26 08:49:50 -05:00
// NOTE: `deno test` always uses `--no-prompt`, tests shouldn't ever do
// interactive prompts, unless done by user code
2024-05-06 19:21:58 -04:00
flags . permissions . no_prompt = true ;
2021-04-16 09:28:41 -04:00
2024-01-15 19:15:39 -05:00
let ignore = match matches . remove_many ::< String > ( " ignore " ) {
2023-03-26 00:06:18 -04:00
Some ( f ) = > f . collect ( ) ,
2021-08-24 11:23:29 -04:00
None = > vec! [ ] ,
} ;
2023-03-26 00:06:18 -04:00
let no_run = matches . get_flag ( " no-run " ) ;
2024-09-02 12:26:05 -04:00
let trace_leaks = matches . get_flag ( " trace-leaks " ) ;
2023-03-26 00:06:18 -04:00
let doc = matches . get_flag ( " doc " ) ;
2024-08-02 09:18:59 -04:00
#[ allow(clippy::print_stderr) ]
2024-09-02 18:06:27 -04:00
let permit_no_files = matches . get_flag ( " permit-no-files " ) ;
2023-03-26 00:06:18 -04:00
let filter = matches . remove_one ::< String > ( " filter " ) ;
2024-05-22 23:04:12 -04:00
let clean = matches . get_flag ( " clean " ) ;
2021-04-16 09:28:41 -04:00
2023-03-26 00:06:18 -04:00
let fail_fast = if matches . contains_id ( " fail-fast " ) {
Some (
matches
. remove_one ::< NonZeroUsize > ( " fail-fast " )
. unwrap_or_else ( | | NonZeroUsize ::new ( 1 ) . unwrap ( ) ) ,
)
2021-07-12 06:55:42 -04:00
} else {
None
} ;
2023-03-26 00:06:18 -04:00
let shuffle = if matches . contains_id ( " shuffle " ) {
Some (
matches
. remove_one ::< u64 > ( " shuffle " )
. unwrap_or_else ( rand ::random ) ,
)
2021-07-05 21:20:33 -04:00
} else {
None
} ;
2021-05-10 02:06:13 -04:00
2023-03-26 00:06:18 -04:00
if let Some ( script_arg ) = matches . remove_many ::< String > ( " script_arg " ) {
flags . argv . extend ( script_arg ) ;
2021-04-16 09:28:41 -04:00
}
2024-09-02 11:26:42 -04:00
let concurrent_jobs = parallel_arg_parse ( matches ) ;
2021-04-28 14:17:04 -04:00
2024-01-15 19:15:39 -05:00
let include = if let Some ( files ) = matches . remove_many ::< String > ( " files " ) {
2023-03-26 00:06:18 -04:00
files . collect ( )
2021-04-16 09:28:41 -04:00
} else {
2022-07-18 15:12:19 -04:00
Vec ::new ( )
2021-04-16 09:28:41 -04:00
} ;
2023-08-02 22:05:34 -04:00
let junit_path = matches . remove_one ::< String > ( " junit-path " ) ;
let reporter =
if let Some ( reporter ) = matches . remove_one ::< String > ( " reporter " ) {
match reporter . as_str ( ) {
" pretty " = > TestReporterConfig ::Pretty ,
" junit " = > TestReporterConfig ::Junit ,
" dot " = > TestReporterConfig ::Dot ,
2023-08-25 19:19:23 -04:00
" tap " = > TestReporterConfig ::Tap ,
2023-08-02 22:05:34 -04:00
_ = > unreachable! ( ) ,
}
} else {
TestReporterConfig ::Pretty
} ;
2023-08-25 19:19:23 -04:00
if matches! ( reporter , TestReporterConfig ::Dot | TestReporterConfig ::Tap ) {
2023-08-02 12:38:10 -04:00
flags . log_level = Some ( Level ::Error ) ;
}
2024-08-19 21:27:36 -04:00
let hide_stacktraces = matches . get_flag ( " hide-stacktraces " ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Test ( TestFlags {
2021-04-16 09:28:41 -04:00
no_run ,
2021-05-10 19:54:39 -04:00
doc ,
2023-06-15 13:09:37 -04:00
coverage_dir : matches . remove_one ::< String > ( " coverage " ) ,
2024-05-22 23:04:12 -04:00
clean ,
2021-04-16 09:28:41 -04:00
fail_fast ,
2023-01-07 15:22:09 -05:00
files : FileFlags { include , ignore } ,
2021-04-16 09:28:41 -04:00
filter ,
2021-07-05 21:20:33 -04:00
shuffle ,
2024-09-02 18:06:27 -04:00
permit_no_files ,
2021-04-28 14:17:04 -04:00
concurrent_jobs ,
2024-02-28 11:12:43 -05:00
trace_leaks ,
2024-08-19 13:09:51 -04:00
watch : watch_arg_parse_with_paths ( matches ) ,
2023-08-02 12:38:10 -04:00
reporter ,
2023-08-02 22:05:34 -04:00
junit_path ,
2024-08-19 21:27:36 -04:00
hide_stacktraces ,
2021-09-03 19:33:35 -04:00
} ) ;
2020-02-17 11:59:51 -05:00
}
2020-04-03 13:40:11 -04:00
2023-03-26 00:06:18 -04:00
fn types_parse ( flags : & mut Flags , _matches : & mut ArgMatches ) {
2021-04-16 09:28:41 -04:00
flags . subcommand = DenoSubcommand ::Types ;
2020-02-17 11:59:51 -05:00
}
2023-03-26 00:06:18 -04:00
fn upgrade_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2021-04-16 09:28:41 -04:00
ca_file_arg_parse ( flags , matches ) ;
2024-08-18 18:39:53 -04:00
unsafely_ignore_certificate_errors_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
2023-03-26 00:06:18 -04:00
let dry_run = matches . get_flag ( " dry-run " ) ;
let force = matches . get_flag ( " force " ) ;
let canary = matches . get_flag ( " canary " ) ;
2024-08-12 14:32:53 -04:00
let release_candidate = matches . get_flag ( " release-candidate " ) ;
2023-03-26 00:06:18 -04:00
let version = matches . remove_one ::< String > ( " version " ) ;
2024-03-14 19:53:46 -04:00
let output = matches . remove_one ::< String > ( " output " ) ;
2024-08-19 11:05:10 -04:00
let version_or_hash_or_channel =
matches . remove_one ::< String > ( " version-or-hash-or-channel " ) ;
2021-09-03 19:33:35 -04:00
flags . subcommand = DenoSubcommand ::Upgrade ( UpgradeFlags {
2021-04-16 09:28:41 -04:00
dry_run ,
force ,
2024-08-12 14:32:53 -04:00
release_candidate ,
2021-04-16 09:28:41 -04:00
canary ,
version ,
output ,
2024-08-19 11:05:10 -04:00
version_or_hash_or_channel ,
2021-09-03 19:33:35 -04:00
} ) ;
2021-01-07 13:06:08 -05:00
}
2024-09-03 03:00:57 -04:00
fn vendor_parse ( flags : & mut Flags , _matches : & mut ArgMatches ) {
flags . subcommand = DenoSubcommand ::Vendor
2022-02-16 13:14:19 -05:00
}
2023-11-23 18:38:07 -05:00
fn publish_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-02-21 08:35:25 -05:00
flags . type_check_mode = TypeCheckMode ::Local ; // local by default
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionOnly ) ;
2024-02-21 08:35:25 -05:00
no_check_arg_parse ( flags , matches ) ;
check_arg_parse ( flags , matches ) ;
2024-02-14 12:13:07 -05:00
config_args_parse ( flags , matches ) ;
2023-11-23 18:38:07 -05:00
flags . subcommand = DenoSubcommand ::Publish ( PublishFlags {
token : matches . remove_one ( " token " ) ,
2024-01-11 16:17:03 -05:00
dry_run : matches . get_flag ( " dry-run " ) ,
2024-02-19 10:28:41 -05:00
allow_slow_types : matches . get_flag ( " allow-slow-types " ) ,
2024-03-07 16:13:36 -05:00
allow_dirty : matches . get_flag ( " allow-dirty " ) ,
2024-02-29 11:18:47 -05:00
no_provenance : matches . get_flag ( " no-provenance " ) ,
2023-11-23 18:38:07 -05:00
} ) ;
}
2023-03-26 00:06:18 -04:00
fn compile_args_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2023-03-13 17:04:00 -04:00
compile_args_without_check_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
no_check_arg_parse ( flags , matches ) ;
2022-06-13 17:13:16 -04:00
check_arg_parse ( flags , matches ) ;
2021-01-07 13:06:08 -05:00
}
2023-03-13 17:04:00 -04:00
fn compile_args_without_check_parse (
2022-04-10 19:12:51 -04:00
flags : & mut Flags ,
2023-03-26 00:06:18 -04:00
matches : & mut ArgMatches ,
2022-04-10 19:12:51 -04:00
) {
import_map_arg_parse ( flags , matches ) ;
no_remote_arg_parse ( flags , matches ) ;
2022-09-07 09:33:51 -04:00
no_npm_arg_parse ( flags , matches ) ;
2023-08-06 21:56:56 -04:00
node_modules_and_vendor_dir_arg_parse ( flags , matches ) ;
2022-05-13 11:40:50 -04:00
config_args_parse ( flags , matches ) ;
2022-04-10 19:12:51 -04:00
reload_arg_parse ( flags , matches ) ;
lock_args_parse ( flags , matches ) ;
ca_file_arg_parse ( flags , matches ) ;
2024-08-18 18:39:53 -04:00
unsafely_ignore_certificate_errors_parse ( flags , matches ) ;
2022-04-10 19:12:51 -04:00
}
2023-03-26 00:06:18 -04:00
fn permission_args_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-03-14 19:53:46 -04:00
if let Some ( read_wl ) = matches . remove_many ::< String > ( " allow-read " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_read = Some ( read_wl . collect ( ) ) ;
2021-04-16 09:28:41 -04:00
}
2024-03-14 19:53:46 -04:00
if let Some ( read_wl ) = matches . remove_many ::< String > ( " deny-read " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_read = Some ( read_wl . collect ( ) ) ;
2023-08-03 07:19:19 -04:00
}
2024-03-14 19:53:46 -04:00
if let Some ( write_wl ) = matches . remove_many ::< String > ( " allow-write " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_write = Some ( write_wl . collect ( ) ) ;
2021-04-16 09:28:41 -04:00
}
2024-03-14 19:53:46 -04:00
if let Some ( write_wl ) = matches . remove_many ::< String > ( " deny-write " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_write = Some ( write_wl . collect ( ) ) ;
2023-08-03 07:19:19 -04:00
}
2023-03-26 00:06:18 -04:00
if let Some ( net_wl ) = matches . remove_many ::< String > ( " allow-net " ) {
2023-08-03 07:19:19 -04:00
let net_allowlist = flags_net ::parse ( net_wl . collect ( ) ) . unwrap ( ) ;
2024-05-06 19:21:58 -04:00
flags . permissions . allow_net = Some ( net_allowlist ) ;
2021-08-09 10:53:21 -04:00
}
2023-08-03 07:19:19 -04:00
if let Some ( net_wl ) = matches . remove_many ::< String > ( " deny-net " ) {
let net_denylist = flags_net ::parse ( net_wl . collect ( ) ) . unwrap ( ) ;
2024-05-06 19:21:58 -04:00
flags . permissions . deny_net = Some ( net_denylist ) ;
2023-08-03 07:19:19 -04:00
}
2023-03-26 00:06:18 -04:00
if let Some ( env_wl ) = matches . remove_many ::< String > ( " allow-env " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_env = Some ( env_wl . collect ( ) ) ;
debug! ( " env allowlist: {:#?} " , & flags . permissions . allow_env ) ;
2021-04-16 09:28:41 -04:00
}
2023-08-03 07:19:19 -04:00
if let Some ( env_wl ) = matches . remove_many ::< String > ( " deny-env " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_env = Some ( env_wl . collect ( ) ) ;
debug! ( " env denylist: {:#?} " , & flags . permissions . deny_env ) ;
2023-08-03 07:19:19 -04:00
}
2023-03-26 00:06:18 -04:00
if let Some ( run_wl ) = matches . remove_many ::< String > ( " allow-run " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_run = Some ( run_wl . collect ( ) ) ;
debug! ( " run allowlist: {:#?} " , & flags . permissions . allow_run ) ;
2021-04-16 09:28:41 -04:00
}
2023-08-03 07:19:19 -04:00
if let Some ( run_wl ) = matches . remove_many ::< String > ( " deny-run " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_run = Some ( run_wl . collect ( ) ) ;
debug! ( " run denylist: {:#?} " , & flags . permissions . deny_run ) ;
2023-08-03 07:19:19 -04:00
}
2023-03-26 00:06:18 -04:00
if let Some ( sys_wl ) = matches . remove_many ::< String > ( " allow-sys " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_sys = Some ( sys_wl . collect ( ) ) ;
debug! ( " sys info allowlist: {:#?} " , & flags . permissions . allow_sys ) ;
2022-09-28 08:46:50 -04:00
}
2023-08-03 07:19:19 -04:00
if let Some ( sys_wl ) = matches . remove_many ::< String > ( " deny-sys " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_sys = Some ( sys_wl . collect ( ) ) ;
debug! ( " sys info denylist: {:#?} " , & flags . permissions . deny_sys ) ;
2023-08-03 07:19:19 -04:00
}
2024-03-14 19:53:46 -04:00
if let Some ( ffi_wl ) = matches . remove_many ::< String > ( " allow-ffi " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . allow_ffi = Some ( ffi_wl . collect ( ) ) ;
debug! ( " ffi allowlist: {:#?} " , & flags . permissions . allow_ffi ) ;
2021-04-16 09:28:41 -04:00
}
2021-08-06 17:28:10 -04:00
2024-03-14 19:53:46 -04:00
if let Some ( ffi_wl ) = matches . remove_many ::< String > ( " deny-ffi " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . deny_ffi = Some ( ffi_wl . collect ( ) ) ;
debug! ( " ffi denylist: {:#?} " , & flags . permissions . deny_ffi ) ;
2023-08-03 07:19:19 -04:00
}
2024-09-03 05:24:25 -04:00
if matches . get_flag ( " allow-hrtime " ) | | matches . get_flag ( " deny-hrtime " ) {
log ::warn! ( " ⚠️ Warning: `allow-hrtime` and `deny-hrtime` have been removed in Deno 2, as high resolution time is now always allowed. " ) ;
2023-08-03 07:19:19 -04:00
}
2023-03-26 00:06:18 -04:00
if matches . get_flag ( " allow-all " ) {
2024-03-13 12:07:24 -04:00
flags . allow_all ( ) ;
2021-04-16 09:28:41 -04:00
}
2023-08-03 07:19:19 -04:00
2023-03-26 00:06:18 -04:00
if matches . get_flag ( " no-prompt " ) {
2024-05-06 19:21:58 -04:00
flags . permissions . no_prompt = true ;
2021-04-16 09:28:41 -04:00
}
2020-03-27 16:09:51 -04:00
}
2023-11-10 12:41:24 -05:00
2022-01-14 11:38:17 -05:00
fn unsafely_ignore_certificate_errors_parse (
2021-12-10 09:47:55 -05:00
flags : & mut Flags ,
2023-03-26 00:06:18 -04:00
matches : & mut ArgMatches ,
2021-12-10 09:47:55 -05:00
) {
2023-03-26 00:06:18 -04:00
if let Some ( ic_wl ) =
matches . remove_many ::< String > ( " unsafely-ignore-certificate-errors " )
{
2023-08-03 07:19:19 -04:00
let ic_allowlist = flags_net ::parse ( ic_wl . collect ( ) ) . unwrap ( ) ;
2021-12-10 09:47:55 -05:00
flags . unsafely_ignore_certificate_errors = Some ( ic_allowlist ) ;
}
}
2023-03-13 17:04:00 -04:00
2021-04-16 09:28:41 -04:00
fn runtime_args_parse (
flags : & mut Flags ,
2023-03-26 00:06:18 -04:00
matches : & mut ArgMatches ,
2021-04-16 09:28:41 -04:00
include_perms : bool ,
include_inspector : bool ,
) {
2024-08-18 18:39:53 -04:00
unstable_args_parse ( flags , matches , UnstableArgsConfig ::ResolutionAndRuntime ) ;
2021-04-16 09:28:41 -04:00
compile_args_parse ( flags , matches ) ;
cached_only_arg_parse ( flags , matches ) ;
2024-07-02 18:00:16 -04:00
frozen_lockfile_arg_parse ( flags , matches ) ;
2021-04-16 09:28:41 -04:00
if include_perms {
permission_args_parse ( flags , matches ) ;
}
if include_inspector {
inspect_arg_parse ( flags , matches ) ;
2020-04-03 13:40:11 -04:00
}
2021-04-16 09:28:41 -04:00
location_arg_parse ( flags , matches ) ;
v8_flags_arg_parse ( flags , matches ) ;
seed_arg_parse ( flags , matches ) ;
2021-07-23 10:31:16 -04:00
enable_testing_features_arg_parse ( flags , matches ) ;
2023-11-01 11:21:13 -04:00
env_file_arg_parse ( flags , matches ) ;
2023-11-10 12:41:24 -05:00
strace_ops_parse ( flags , matches ) ;
2020-04-03 13:40:11 -04:00
}
2023-03-26 00:06:18 -04:00
fn inspect_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-21 09:54:59 -04:00
flags . inspect = matches . remove_one ::< SocketAddr > ( " inspect " ) ;
flags . inspect_brk = matches . remove_one ::< SocketAddr > ( " inspect-brk " ) ;
flags . inspect_wait = matches . remove_one ::< SocketAddr > ( " inspect-wait " ) ;
2020-03-27 16:09:51 -04:00
}
2023-03-26 00:06:18 -04:00
fn import_map_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . import_map_path = matches . remove_one ::< String > ( " import-map " ) ;
2019-11-26 11:06:32 -05:00
}
2019-08-15 10:11:52 -04:00
2023-11-01 11:21:13 -04:00
fn env_file_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2024-08-08 09:50:57 -04:00
flags . env_file = matches . remove_one ::< String > ( " env-file " ) ;
2023-11-01 11:21:13 -04:00
}
2023-03-26 00:06:18 -04:00
fn reload_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( cache_bl ) = matches . remove_many ::< String > ( " reload " ) {
let raw_cache_blocklist : Vec < String > = cache_bl . collect ( ) ;
2020-06-13 13:09:39 -04:00
if raw_cache_blocklist . is_empty ( ) {
2020-05-16 09:41:32 -04:00
flags . reload = true ;
} else {
2020-06-13 13:09:39 -04:00
flags . cache_blocklist = resolve_urls ( raw_cache_blocklist ) ;
debug! ( " cache blocklist: {:#?} " , & flags . cache_blocklist ) ;
2019-11-26 11:06:32 -05:00
flags . reload = false ;
2019-05-03 17:15:16 -04:00
}
2019-11-26 11:06:32 -05:00
}
}
2019-10-04 09:02:36 -04:00
2023-03-26 00:06:18 -04:00
fn ca_file_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . ca_data = matches . remove_one ::< String > ( " cert " ) . map ( CaData ::File ) ;
2019-11-26 11:06:32 -05:00
}
2019-10-04 09:02:36 -04:00
2021-07-23 10:31:16 -04:00
fn enable_testing_features_arg_parse (
flags : & mut Flags ,
2023-03-26 00:06:18 -04:00
matches : & mut ArgMatches ,
2021-07-23 10:31:16 -04:00
) {
2023-03-26 00:06:18 -04:00
if matches . get_flag ( " enable-testing-features-do-not-use " ) {
2021-07-23 10:31:16 -04:00
flags . enable_testing_features = true
}
}
2023-11-10 12:41:24 -05:00
fn strace_ops_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( patterns ) = matches . remove_many ::< String > ( " strace-ops " ) {
flags . strace_ops = Some ( patterns . collect ( ) ) ;
}
}
2023-03-26 00:06:18 -04:00
fn cached_only_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if matches . get_flag ( " cached-only " ) {
2021-04-16 09:28:41 -04:00
flags . cached_only = true ;
}
2019-11-26 11:06:32 -05:00
}
2019-10-04 09:02:36 -04:00
2024-07-02 18:00:16 -04:00
fn frozen_lockfile_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( & v ) = matches . get_one ::< bool > ( " frozen " ) {
2024-08-20 10:55:47 -04:00
flags . frozen_lockfile = Some ( v ) ;
2024-07-02 18:00:16 -04:00
}
}
2023-03-26 00:06:18 -04:00
fn ext_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . ext = matches . remove_one ::< String > ( " ext " ) ;
2023-03-22 10:15:53 -04:00
}
2023-03-26 00:06:18 -04:00
fn location_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . location = matches . remove_one ::< Url > ( " location " ) ;
2019-11-26 23:25:14 -05:00
}
2023-03-26 00:06:18 -04:00
fn v8_flags_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( v8_flags ) = matches . remove_many ::< String > ( " v8-flags " ) {
flags . v8_flags = v8_flags . collect ( ) ;
2019-11-26 23:25:14 -05:00
}
}
2023-03-26 00:06:18 -04:00
fn seed_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( seed ) = matches . remove_one ::< u64 > ( " seed " ) {
2020-09-18 13:09:11 -04:00
flags . seed = Some ( seed ) ;
2023-01-27 10:43:16 -05:00
flags . v8_flags . push ( format! ( " --random-seed= {seed} " ) ) ;
2020-09-18 13:09:11 -04:00
}
}
2023-03-26 00:06:18 -04:00
fn no_check_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( cache_type ) = matches . get_one ::< String > ( " no-check " ) {
match cache_type . as_str ( ) {
2022-04-10 19:12:51 -04:00
" remote " = > flags . type_check_mode = TypeCheckMode ::Local ,
2021-11-29 17:23:30 -05:00
_ = > debug! (
" invalid value for 'no-check' of '{}' using default " ,
cache_type
) ,
}
2023-03-26 00:06:18 -04:00
} else if matches . contains_id ( " no-check " ) {
2022-04-10 19:12:51 -04:00
flags . type_check_mode = TypeCheckMode ::None ;
}
}
2023-03-26 00:06:18 -04:00
fn check_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if let Some ( cache_type ) = matches . get_one ::< String > ( " check " ) {
match cache_type . as_str ( ) {
2022-06-13 17:13:16 -04:00
" all " = > flags . type_check_mode = TypeCheckMode ::All ,
2022-04-10 19:12:51 -04:00
_ = > debug! (
" invalid value for 'check' of '{}' using default " ,
cache_type
) ,
}
2023-03-26 00:06:18 -04:00
} else if matches . contains_id ( " check " ) {
2022-06-13 17:13:16 -04:00
flags . type_check_mode = TypeCheckMode ::Local ;
2020-07-08 05:26:39 -04:00
}
}
2023-03-26 00:06:18 -04:00
fn lock_args_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
2022-02-16 13:14:19 -05:00
lock_arg_parse ( flags , matches ) ;
2023-03-13 17:04:00 -04:00
no_lock_arg_parse ( flags , matches ) ;
2022-02-16 13:14:19 -05:00
}
2023-03-26 00:06:18 -04:00
fn lock_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if matches . contains_id ( " lock " ) {
2024-08-12 11:55:33 -04:00
let lockfile = matches . remove_one ::< String > ( " lock " ) . unwrap ( ) ;
2023-03-26 00:06:18 -04:00
flags . lock = Some ( lockfile ) ;
2021-04-16 09:28:41 -04:00
}
}
2023-03-26 00:06:18 -04:00
fn no_lock_arg_parse ( flags : & mut Flags , matches : & ArgMatches ) {
if matches . get_flag ( " no-lock " ) {
2023-03-13 17:04:00 -04:00
flags . no_lock = true ;
}
}
2023-03-26 00:06:18 -04:00
fn config_args_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
flags . config_flag = if matches . get_flag ( " no-config " ) {
2022-05-13 11:40:50 -04:00
ConfigFlag ::Disabled
2023-03-26 00:06:18 -04:00
} else if let Some ( config ) = matches . remove_one ::< String > ( " config " ) {
ConfigFlag ::Path ( config )
2022-05-13 11:40:50 -04:00
} else {
ConfigFlag ::Discover
} ;
2019-12-03 17:48:53 -05:00
}
2023-03-26 00:06:18 -04:00
fn no_remote_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if matches . get_flag ( " no-remote " ) {
2019-12-03 17:48:53 -05:00
flags . no_remote = true ;
}
}
2023-03-26 00:06:18 -04:00
fn no_npm_arg_parse ( flags : & mut Flags , matches : & mut ArgMatches ) {
if matches . get_flag ( " no-npm " ) {
2022-09-07 09:33:51 -04:00
flags . no_npm = true ;
}
}
2023-08-06 21:56:56 -04:00
fn node_modules_and_vendor_dir_arg_parse (
2023-08-01 20:49:09 -04:00
flags : & mut Flags ,
matches : & mut ArgMatches ,
) {
2024-08-29 18:57:43 -04:00
node_modules_arg_parse ( flags , matches ) ;
2023-08-06 21:56:56 -04:00
flags . vendor = matches . remove_one ::< bool > ( " vendor " ) ;
2020-01-30 18:42:39 -05:00
}
2023-03-26 00:06:18 -04:00
fn reload_arg_validate ( urlstr : & str ) -> Result < String , String > {
2022-09-06 12:30:42 -04:00
if urlstr . is_empty ( ) {
return Err ( String ::from ( " Missing url. Check for extra commas. " ) ) ;
}
match Url ::from_str ( urlstr ) {
2023-03-26 00:06:18 -04:00
Ok ( _ ) = > Ok ( urlstr . to_string ( ) ) ,
2022-09-06 12:30:42 -04:00
Err ( e ) = > Err ( e . to_string ( ) ) ,
}
}
2023-06-15 13:09:37 -04:00
fn watch_arg_parse ( matches : & mut ArgMatches ) -> Option < WatchFlags > {
if matches . get_flag ( " watch " ) {
Some ( WatchFlags {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
no_clear_screen : matches . get_flag ( " no-clear-screen " ) ,
2024-03-27 18:47:46 -04:00
exclude : matches
. remove_many ::< String > ( " watch-exclude " )
. map ( | f | f . collect ::< Vec < String > > ( ) )
. unwrap_or_default ( ) ,
2023-06-15 13:09:37 -04:00
} )
} else {
None
2021-12-15 16:04:43 -05:00
}
2023-06-15 13:09:37 -04:00
}
2022-01-31 11:39:39 -05:00
2023-06-15 13:09:37 -04:00
fn watch_arg_parse_with_paths (
matches : & mut ArgMatches ,
) -> Option < WatchFlagsWithPaths > {
2024-03-14 19:53:46 -04:00
if let Some ( paths ) = matches . remove_many ::< String > ( " watch " ) {
2023-10-30 20:25:58 -04:00
return Some ( WatchFlagsWithPaths {
paths : paths . collect ( ) ,
hmr : false ,
no_clear_screen : matches . get_flag ( " no-clear-screen " ) ,
2024-03-27 18:47:46 -04:00
exclude : matches
. remove_many ::< String > ( " watch-exclude " )
. map ( | f | f . collect ::< Vec < String > > ( ) )
. unwrap_or_default ( ) ,
2023-10-30 20:25:58 -04:00
} ) ;
}
2024-08-19 13:09:51 -04:00
if matches . try_contains_id ( " hmr " ) . is_ok ( ) {
return matches . remove_many ::< String > ( " hmr " ) . map ( | paths | {
WatchFlagsWithPaths {
paths : paths . collect ( ) ,
hmr : true ,
no_clear_screen : matches . get_flag ( " no-clear-screen " ) ,
exclude : matches
. remove_many ::< String > ( " watch-exclude " )
. map ( | f | f . collect ::< Vec < String > > ( ) )
. unwrap_or_default ( ) ,
}
} ) ;
}
None
2021-12-15 16:04:43 -05:00
}
2024-08-18 18:39:53 -04:00
fn unstable_args_parse (
flags : & mut Flags ,
matches : & mut ArgMatches ,
cfg : UnstableArgsConfig ,
) {
if matches . get_flag ( " unstable " ) {
flags . unstable_config . legacy_flag_enabled = true ;
}
flags . unstable_config . bare_node_builtins =
matches . get_flag ( " unstable-bare-node-builtins " ) ;
flags . unstable_config . sloppy_imports =
matches . get_flag ( " unstable-sloppy-imports " ) ;
if matches! ( cfg , UnstableArgsConfig ::ResolutionAndRuntime ) {
2024-08-27 07:45:27 -04:00
for granular_flag in crate ::UNSTABLE_GRANULAR_FLAGS {
if matches . get_flag ( & format! ( " unstable- {} " , granular_flag . name ) ) {
flags
. unstable_config
. features
. push ( granular_flag . name . to_string ( ) ) ;
2024-08-18 18:39:53 -04:00
}
}
}
}
2019-11-26 11:06:32 -05:00
// TODO(ry) move this to utility module and add test.
/// Strips fragment part of URL. Panics on bad URL.
pub fn resolve_urls ( urls : Vec < String > ) -> Vec < String > {
let mut out : Vec < String > = vec! [ ] ;
for urlstr in urls . iter ( ) {
2020-11-12 17:17:31 -05:00
if let Ok ( mut url ) = Url ::from_str ( urlstr ) {
url . set_fragment ( None ) ;
let mut full_url = String ::from ( url . as_str ( ) ) ;
if full_url . len ( ) > 1 & & full_url . ends_with ( '/' ) {
full_url . pop ( ) ;
}
out . push ( full_url ) ;
} else {
2023-01-27 10:43:16 -05:00
panic! ( " Bad Url: {urlstr} " ) ;
2019-06-05 13:44:46 -04:00
}
2019-11-26 11:06:32 -05:00
}
out
2019-04-29 19:43:06 -04:00
}
2019-11-26 11:06:32 -05:00
#[ cfg(test) ]
mod tests {
use super ::* ;
2022-04-27 15:43:36 -04:00
use pretty_assertions ::assert_eq ;
2019-11-26 11:06:32 -05:00
2020-12-06 12:19:21 -05:00
/// Creates vector of strings, Vec<String>
macro_rules ! svec {
2024-03-22 17:03:56 -04:00
( $( $x :expr ) , * $(, ) ? ) = > ( vec! [ $( $x . to_string ( ) . into ( ) ) , * ] ) ;
2022-02-16 13:14:19 -05:00
}
2020-12-06 12:19:21 -05:00
2020-09-20 07:45:00 -04:00
#[ test ]
fn global_flags ( ) {
#[ rustfmt::skip ]
2024-08-18 18:39:53 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --log-level " , " debug " , " --quiet " , " run " , " script.ts " ] ) ;
2023-01-07 15:22:09 -05:00
2020-09-20 07:45:00 -04:00
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( )
) ) ,
2020-09-20 07:45:00 -04:00
log_level : Some ( Level ::Error ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-09-20 07:45:00 -04:00
.. Flags ::default ( )
}
) ;
#[ rustfmt::skip ]
2024-08-18 18:39:53 -04:00
let r2 = flags_from_vec ( svec! [ " deno " , " run " , " --log-level " , " debug " , " --quiet " , " script.ts " ] ) ;
2020-09-20 07:45:00 -04:00
let flags2 = r2 . unwrap ( ) ;
assert_eq! ( flags2 , flags ) ;
}
2020-03-23 11:37:24 -04:00
#[ test ]
fn upgrade ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --dry-run " , " --force " ] ) ;
2020-03-23 11:37:24 -04:00
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Upgrade ( UpgradeFlags {
2020-03-23 11:37:24 -04:00
force : true ,
dry_run : true ,
2020-11-29 14:00:35 -05:00
canary : false ,
2024-08-12 14:32:53 -04:00
release_candidate : false ,
2020-07-05 23:58:23 -04:00
version : None ,
2020-07-06 18:21:26 -04:00
output : None ,
2024-08-19 11:05:10 -04:00
version_or_hash_or_channel : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-03-23 11:37:24 -04:00
.. Flags ::default ( )
}
) ;
}
2024-03-14 19:53:46 -04:00
#[ test ]
fn upgrade_with_output_flag ( ) {
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --output " , " example.txt " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Upgrade ( UpgradeFlags {
force : false ,
dry_run : false ,
canary : false ,
2024-08-12 14:32:53 -04:00
release_candidate : false ,
2024-03-14 19:53:46 -04:00
version : None ,
output : Some ( String ::from ( " example.txt " ) ) ,
2024-08-19 11:05:10 -04:00
version_or_hash_or_channel : None ,
2024-03-14 19:53:46 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
}
2019-11-26 11:06:32 -05:00
#[ test ]
fn version ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " --version " ] ) ;
2023-03-26 00:06:18 -04:00
assert_eq! (
r . unwrap_err ( ) . kind ( ) ,
clap ::error ::ErrorKind ::DisplayVersion
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " -V " ] ) ;
2023-03-26 00:06:18 -04:00
assert_eq! (
r . unwrap_err ( ) . kind ( ) ,
clap ::error ::ErrorKind ::DisplayVersion
) ;
2019-04-21 11:34:18 -04:00
}
2018-08-24 15:26:40 -04:00
2019-04-21 11:34:18 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn run_reload ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " -r " , " script.ts " ] ) ;
2019-11-26 11:06:32 -05:00
let flags = r . unwrap ( ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
flags ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( )
) ) ,
2019-04-21 11:34:18 -04:00
reload : true ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
) ;
}
2018-10-11 17:23:22 -04:00
2020-09-11 12:19:49 -04:00
#[ test ]
fn run_watch ( ) {
2021-04-27 06:44:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --watch " , " script.ts " ] ) ;
2020-09-11 12:19:49 -04:00
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
2020-09-11 12:19:49 -04:00
script : " script.ts " . to_string ( ) ,
2023-06-15 13:09:37 -04:00
watch : Some ( WatchFlagsWithPaths {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
paths : vec ! [ ] ,
no_clear_screen : false ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-06-15 13:09:37 -04:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-12-15 16:04:43 -05:00
.. Flags ::default ( )
}
) ;
2023-10-30 20:25:58 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" --watch " ,
" --no-clear-screen " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ ] ,
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : true ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-10-30 20:25:58 -04:00
.. Flags ::default ( )
}
) ;
2024-08-11 18:10:55 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --watch-hmr " ,
" --no-clear-screen " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : true ,
paths : vec ! [ ] ,
no_clear_screen : true ,
exclude : vec ! [ ] ,
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2024-08-11 18:10:55 -04:00
} ) ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
2023-10-30 20:25:58 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --unstable-hmr " ,
" --no-clear-screen " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : true ,
paths : vec ! [ ] ,
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-10-30 20:25:58 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2024-08-11 18:10:55 -04:00
" --watch-hmr=foo.txt " ,
2023-10-30 20:25:58 -04:00
" --no-clear-screen " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : true ,
2024-03-14 19:53:46 -04:00
paths : vec ! [ String ::from ( " foo.txt " ) ] ,
2023-10-30 20:25:58 -04:00
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2023-10-30 20:25:58 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-10-30 20:25:58 -04:00
.. Flags ::default ( )
}
) ;
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --hmr " , " --watch " , " script.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
2021-12-15 16:04:43 -05:00
}
#[ test ]
fn run_watch_with_external ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --watch=file1,file2 " , " script.ts " ] ) ;
2021-12-15 16:04:43 -05:00
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
2023-06-15 13:09:37 -04:00
watch : Some ( WatchFlagsWithPaths {
2023-10-30 20:25:58 -04:00
hmr : false ,
2024-03-14 19:53:46 -04:00
paths : vec ! [ String ::from ( " file1 " ) , String ::from ( " file2 " ) ] ,
2023-06-15 13:09:37 -04:00
no_clear_screen : false ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-06-15 13:09:37 -04:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : true ,
2021-12-15 16:04:43 -05:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-09-11 12:19:49 -04:00
.. Flags ::default ( )
}
) ;
}
2022-01-31 11:39:39 -05:00
#[ test ]
fn run_watch_with_no_clear_screen ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --watch " ,
" --no-clear-screen " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
2023-06-15 13:09:37 -04:00
watch : Some ( WatchFlagsWithPaths {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
paths : vec ! [ ] ,
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2024-03-27 18:47:46 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2024-03-27 18:47:46 -04:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn run_watch_with_excluded_paths ( ) {
let r = flags_from_vec ( svec! (
" deno " ,
" --watch " ,
" --watch-exclude=foo " ,
" script.ts "
) ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " foo " ) ] ,
} ) ,
2024-08-12 11:55:33 -04:00
bare : true ,
2024-03-27 18:47:46 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2024-03-27 18:47:46 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! (
" deno " ,
" run " ,
" --watch=foo " ,
" --watch-exclude=bar " ,
" script.ts "
) ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " bar " ) ] ,
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2024-03-27 18:47:46 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2024-03-27 18:47:46 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --watch " ,
" --watch-exclude=foo,bar " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " foo " ) , String ::from ( " bar " ) ] ,
} ) ,
2024-08-12 11:55:33 -04:00
bare : false ,
2024-03-27 18:47:46 -04:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2024-03-27 18:47:46 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" --watch=foo,bar " ,
" --watch-exclude=baz,qux " ,
" script.ts "
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) , String ::from ( " bar " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " baz " ) , String ::from ( " qux " ) , ] ,
2023-12-06 16:36:06 -05:00
} ) ,
2024-08-12 11:55:33 -04:00
bare : true ,
2022-01-31 11:39:39 -05:00
} ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-01-31 11:39:39 -05:00
.. Flags ::default ( )
}
) ;
}
2019-04-21 11:34:18 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn run_reload_allow_write ( ) {
2021-01-07 13:06:08 -05:00
let r =
flags_from_vec ( svec! [ " deno " , " run " , " -r " , " --allow-write " , " script.ts " ] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2019-04-21 11:34:18 -04:00
reload : true ,
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( )
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_write : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
) ;
}
2018-10-15 14:26:22 -04:00
2019-04-21 11:34:18 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn run_v8_flags ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --v8-flags=--help " ] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default ( " _ " . to_string ( ) ) ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --help " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
) ;
2019-01-09 11:59:54 -05:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-05-03 17:15:16 -04:00
" deno " ,
" run " ,
2019-11-26 11:06:32 -05:00
" --v8-flags=--expose-gc,--gc-stats=1 " ,
2019-05-03 17:15:16 -04:00
" script.ts "
] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
2024-04-24 15:45:49 -04:00
" script.ts " . to_string ( ) ,
2023-12-06 16:36:06 -05:00
) ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --expose-gc " , " --gc-stats=1 " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
) ;
2023-08-12 22:04:17 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --v8-flags=--expose-gc " ] ) ;
2024-08-21 09:54:59 -04:00
assert! ( r . is_ok ( ) ) ;
2019-04-21 11:34:18 -04:00
}
2024-04-24 15:45:49 -04:00
#[ test ]
fn serve_flags ( ) {
let r = flags_from_vec ( svec! [ " deno " , " serve " , " main.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
8000 ,
" 0.0.0.0 "
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [
" 0.0.0.0:8000 " . to_string ( ) ,
" 127.0.0.1:8000 " . to_string ( ) ,
" localhost:8000 " . to_string ( )
] ) ,
.. Default ::default ( )
} ,
2024-04-24 15:45:49 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " serve " , " --port " , " 5000 " , " main.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
5000 ,
" 0.0.0.0 "
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [
" 0.0.0.0:5000 " . to_string ( ) ,
" 127.0.0.1:5000 " . to_string ( ) ,
" localhost:5000 " . to_string ( )
] ) ,
.. Default ::default ( )
} ,
2024-04-24 15:45:49 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" serve " ,
" --port " ,
" 5000 " ,
" --allow-net=example.com " ,
" main.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
5000 ,
" 0.0.0.0 "
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [
" example.com " . to_string ( ) ,
" 0.0.0.0:5000 " . to_string ( ) ,
" 127.0.0.1:5000 " . to_string ( ) ,
" localhost:5000 " . to_string ( )
] ) ,
.. Default ::default ( )
} ,
2024-04-24 15:45:49 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" serve " ,
" --port " ,
" 5000 " ,
" --allow-net " ,
" main.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
5000 ,
" 0.0.0.0 "
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-24 15:45:49 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" serve " ,
" --port " ,
" 5000 " ,
" --host " ,
" example.com " ,
" main.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
5000 ,
" example.com "
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ " example.com:5000 " . to_owned ( ) ] ) ,
.. Default ::default ( )
} ,
2024-04-24 15:45:49 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
2024-05-17 01:38:50 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" serve " ,
" --port " ,
" 0 " ,
" --host " ,
" example.com " ,
" main.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Serve ( ServeFlags ::new_default (
" main.ts " . to_string ( ) ,
0 ,
" example.com "
) ) ,
permissions : PermissionFlags {
allow_net : Some ( vec! [ " example.com:0 " . to_owned ( ) ] ) ,
.. Default ::default ( )
} ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
2024-04-24 15:45:49 -04:00
}
2022-11-23 22:00:31 -05:00
#[ test ]
fn has_permission ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --allow-read " , " x.ts " ] ) ;
2022-11-23 22:00:31 -05:00
assert_eq! ( r . unwrap ( ) . has_permission ( ) , true ) ;
2023-08-03 07:19:19 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --deny-read " , " x.ts " ] ) ;
assert_eq! ( r . unwrap ( ) . has_permission ( ) , true ) ;
2022-11-23 22:00:31 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " x.ts " ] ) ;
assert_eq! ( r . unwrap ( ) . has_permission ( ) , false ) ;
}
#[ test ]
fn has_permission_in_argv ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " x.ts " , " --allow-read " ] ) ;
assert_eq! ( r . unwrap ( ) . has_permission_in_argv ( ) , true ) ;
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " x.ts " , " --deny-read " ] ) ;
2023-08-03 07:19:19 -04:00
assert_eq! ( r . unwrap ( ) . has_permission_in_argv ( ) , true ) ;
2022-11-23 22:00:31 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " x.ts " ] ) ;
assert_eq! ( r . unwrap ( ) . has_permission_in_argv ( ) , false ) ;
}
2019-04-21 11:34:18 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn script_args ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-05-03 17:15:16 -04:00
" deno " ,
" run " ,
" --allow-net " ,
" gist.ts " ,
" --title " ,
" X "
] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" gist.ts " . to_string ( )
) ) ,
2020-02-04 14:24:33 -05:00
argv : svec ! [ " --title " , " X " ] ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
2019-04-29 19:43:06 -04:00
) ;
2019-04-21 11:34:18 -04:00
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn allow_all ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --allow-all " , " gist.ts " ] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" gist.ts " . to_string ( )
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
2019-04-29 19:43:06 -04:00
) ;
2019-04-21 11:34:18 -04:00
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn allow_read ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --allow-read " , " gist.ts " ] ) ;
2019-04-21 11:34:18 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" gist.ts " . to_string ( )
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_read : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
2019-04-29 19:43:06 -04:00
) ;
2019-04-21 11:34:18 -04:00
}
2024-08-08 09:46:10 -04:00
#[ test ]
fn short_permission_flags ( ) {
2024-08-18 18:39:53 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " -RNESW " , " gist.ts " ] ) ;
2024-08-08 09:46:10 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" gist.ts " . to_string ( )
) ) ,
permissions : PermissionFlags {
allow_read : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
2024-08-18 18:39:53 -04:00
allow_env : Some ( vec! [ ] ) ,
allow_net : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
2024-08-08 09:46:10 -04:00
.. Default ::default ( )
} ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_read ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --deny-read " , " gist.ts " ] ) ;
2023-08-03 07:19:19 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " gist.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_read : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2019-04-21 11:34:18 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn double_hyphen ( ) {
2019-06-29 18:32:54 -04:00
// notice that flags passed after double dash will not
2020-02-26 05:52:15 -05:00
// be parsed to Flags but instead forwarded to
2019-04-21 11:34:18 -04:00
// script args as Deno.args
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-04-21 11:34:18 -04:00
" deno " ,
2019-05-03 17:15:16 -04:00
" run " ,
2019-04-21 11:34:18 -04:00
" --allow-write " ,
" script.ts " ,
2019-06-29 18:32:54 -04:00
" -- " ,
2019-04-21 11:34:18 -04:00
" -D " ,
" --allow-net "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-02-04 14:24:33 -05:00
argv : svec ! [ " -- " , " -D " , " --allow-net " ] ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_write : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-21 11:34:18 -04:00
}
2019-04-29 19:43:06 -04:00
) ;
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn fmt ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " fmt " , " script_1.ts " , " script_2.ts " ] ) ;
2019-04-29 19:43:06 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
2020-01-29 21:16:48 -05:00
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) , " script_2.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2020-01-29 21:16:48 -05:00
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " fmt " , " --check " ] ) ;
2020-01-29 21:16:48 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
2020-01-29 21:16:48 -05:00
check : true ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-04-29 19:43:06 -04:00
}
) ;
2020-02-09 05:19:05 -05:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " fmt " ] ) ;
2020-02-09 05:19:05 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
2020-02-09 05:19:05 -05:00
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2020-02-09 05:19:05 -05:00
}
) ;
2020-11-22 15:45:44 -05:00
2021-04-27 06:44:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " fmt " , " --watch " ] ) ;
2020-11-22 15:45:44 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
2020-11-22 15:45:44 -05:00
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-11-22 15:45:44 -05:00
.. Flags ::default ( )
}
) ;
2024-08-02 09:52:48 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" fmt " ,
" --watch " ,
" --no-clear-screen " ,
2024-08-09 12:52:23 -04:00
" --unstable-css " ,
2024-08-14 16:58:48 -04:00
" --unstable-html " ,
" --unstable-component " ,
2024-08-02 09:52:48 -04:00
" --unstable-yaml "
] ) ;
2022-01-31 11:39:39 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2022-01-31 11:39:39 -05:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : true ,
2024-08-14 16:58:48 -04:00
unstable_html : true ,
unstable_component : true ,
2024-08-02 09:52:48 -04:00
unstable_yaml : true ,
2023-06-15 13:09:37 -04:00
watch : Some ( WatchFlags {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2023-06-15 13:09:37 -04:00
} )
2022-01-31 11:39:39 -05:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2022-01-31 11:39:39 -05:00
.. Flags ::default ( )
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-11-22 15:45:44 -05:00
" deno " ,
" fmt " ,
" --check " ,
" --watch " ,
" foo.ts " ,
" --ignore=bar.js "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
2020-11-22 15:45:44 -05:00
check : true ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " foo.ts " . to_string ( ) ] ,
ignore : vec ! [ " bar.js " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2021-09-13 14:19:10 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " fmt " , " --config " , " deno.jsonc " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2021-09-13 14:19:10 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " deno.jsonc " . to_string ( ) ) ,
2021-09-13 14:19:10 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" fmt " ,
" --config " ,
" deno.jsonc " ,
" --watch " ,
" foo.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " foo.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : None ,
line_width : None ,
indent_width : None ,
single_quote : None ,
prose_wrap : None ,
2023-01-25 15:06:00 -05:00
no_semicolons : None ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2021-09-13 14:19:10 -04:00
} ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " deno.jsonc " . to_string ( ) ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-11-22 15:45:44 -05:00
.. Flags ::default ( )
}
) ;
2021-09-13 16:06:45 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" fmt " ,
2023-02-11 12:39:56 -05:00
" --use-tabs " ,
" --line-width " ,
2021-09-13 16:06:45 -04:00
" 60 " ,
2023-02-11 12:39:56 -05:00
" --indent-width " ,
2021-09-13 16:06:45 -04:00
" 4 " ,
2023-02-11 12:39:56 -05:00
" --single-quote " ,
" --prose-wrap " ,
2023-01-24 15:07:00 -05:00
" never " ,
2023-02-11 12:39:56 -05:00
" --no-semicolons " ,
2021-09-13 16:06:45 -04:00
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
check : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2021-09-13 16:06:45 -04:00
use_tabs : Some ( true ) ,
line_width : Some ( NonZeroU32 ::new ( 60 ) . unwrap ( ) ) ,
indent_width : Some ( NonZeroU8 ::new ( 4 ) . unwrap ( ) ) ,
single_quote : Some ( true ) ,
prose_wrap : Some ( " never " . to_string ( ) ) ,
2023-01-25 15:06:00 -05:00
no_semicolons : Some ( true ) ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2023-01-25 15:06:00 -05:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2023-01-25 15:06:00 -05:00
.. Flags ::default ( )
}
) ;
// try providing =false to the booleans
let r = flags_from_vec ( svec! [
" deno " ,
" fmt " ,
2023-02-11 12:39:56 -05:00
" --use-tabs=false " ,
" --single-quote=false " ,
" --no-semicolons=false " ,
2023-01-25 15:06:00 -05:00
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Fmt ( FmtFlags {
check : false ,
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
use_tabs : Some ( false ) ,
line_width : None ,
indent_width : None ,
single_quote : Some ( false ) ,
prose_wrap : None ,
no_semicolons : Some ( false ) ,
2024-08-09 12:52:23 -04:00
unstable_css : false ,
2024-08-14 16:58:48 -04:00
unstable_html : false ,
unstable_component : false ,
2024-08-02 09:52:48 -04:00
unstable_yaml : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2021-09-13 16:06:45 -04:00
} ) ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2021-09-13 16:06:45 -04:00
.. Flags ::default ( )
}
) ;
2019-04-29 19:43:06 -04:00
}
2020-06-10 17:29:48 -04:00
#[ test ]
fn lint ( ) {
2021-04-27 06:44:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " lint " , " script_1.ts " , " script_2.ts " ] ) ;
2020-06-10 17:29:48 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) , " script_2.ts " . to_string ( ) , ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2020-06-12 10:42:12 -04:00
rules : false ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
2020-08-13 11:30:46 -04:00
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-06-10 17:29:48 -04:00
.. Flags ::default ( )
}
) ;
2022-01-31 11:39:39 -05:00
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --watch " ,
" script_1.ts " ,
" script_2.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) , " script_2.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2022-01-31 11:39:39 -05:00
rules : false ,
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2022-01-31 11:39:39 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --watch " ,
" --no-clear-screen " ,
" script_1.ts " ,
" script_2.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) , " script_2.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2022-01-31 11:39:39 -05:00
rules : false ,
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Some ( WatchFlags {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2024-08-19 16:42:13 -04:00
} ) ,
ext : None ,
2022-01-31 11:39:39 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
2024-03-21 17:18:59 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --fix " ,
" --ignore=script_1.ts,script_2.ts "
] ) ;
2020-06-10 17:29:48 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
2024-01-15 19:15:39 -05:00
ignore : vec ! [ " script_1.ts " . to_string ( ) , " script_2.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
} ,
2024-03-21 17:18:59 -04:00
fix : true ,
2020-06-12 10:42:12 -04:00
rules : false ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
2020-08-13 11:30:46 -04:00
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-06-12 10:42:12 -04:00
.. Flags ::default ( )
}
) ;
2021-04-27 06:44:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " lint " , " --rules " ] ) ;
2020-06-12 10:42:12 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2020-08-12 09:47:44 -04:00
rules : true ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
2021-09-03 11:01:58 -04:00
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2021-09-03 11:01:58 -04:00
.. Flags ::default ( )
}
) ;
2023-07-25 17:24:06 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --rules " ,
" --rules-tags=recommended "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Lint ( LintFlags {
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2023-07-25 17:24:06 -04:00
rules : true ,
maybe_rules_tags : Some ( svec! [ " recommended " ] ) ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
json : false ,
compact : false ,
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2023-07-25 17:24:06 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
2021-09-03 11:01:58 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --rules-tags= " ,
" --rules-include=ban-untagged-todo,no-undef " ,
" --rules-exclude=no-const-assign "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2021-09-03 11:01:58 -04:00
rules : false ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : Some ( svec! [ " " ] ) ,
maybe_rules_include : Some ( svec! [ " ban-untagged-todo " , " no-undef " ] ) ,
maybe_rules_exclude : Some ( svec! [ " no-const-assign " ] ) ,
2020-08-13 11:30:46 -04:00
json : false ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-08-13 11:30:46 -04:00
.. Flags ::default ( )
}
) ;
2021-04-27 06:44:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " lint " , " --json " , " script_1.ts " ] ) ;
2020-08-13 11:30:46 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2020-08-13 11:30:46 -04:00
rules : false ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
2021-09-03 11:01:58 -04:00
json : true ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2021-09-03 11:01:58 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --config " ,
" Deno.jsonc " ,
" --json " ,
" script_1.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2021-09-03 11:01:58 -04:00
rules : false ,
2021-11-04 11:12:12 -04:00
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
2020-08-13 11:30:46 -04:00
json : true ,
2022-09-28 12:47:48 -04:00
compact : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2022-09-28 12:47:48 -04:00
} ) ,
config_flag : ConfigFlag ::Path ( " Deno.jsonc " . to_string ( ) ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" lint " ,
" --config " ,
" Deno.jsonc " ,
" --compact " ,
" script_1.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Lint ( LintFlags {
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " script_1.ts " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2024-03-21 17:18:59 -04:00
fix : false ,
2022-09-28 12:47:48 -04:00
rules : false ,
maybe_rules_tags : None ,
maybe_rules_include : None ,
maybe_rules_exclude : None ,
json : false ,
compact : true ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2024-08-19 16:42:13 -04:00
ext : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " Deno.jsonc " . to_string ( ) ) ,
2020-06-10 17:29:48 -04:00
.. Flags ::default ( )
}
) ;
}
2019-04-29 19:43:06 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn types ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " types " ] ) ;
2019-11-26 11:06:32 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2019-11-26 11:06:32 -05:00
subcommand : DenoSubcommand ::Types ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-11-26 11:06:32 -05:00
}
) ;
2019-04-29 19:43:06 -04:00
}
#[ test ]
2020-04-07 11:24:47 -04:00
fn cache ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " cache " , " script.ts " ] ) ;
2019-11-26 11:06:32 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Cache ( CacheFlags {
2020-02-04 14:24:33 -05:00
files : svec ! [ " script.ts " ] ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-11-26 11:06:32 -05:00
}
) ;
2019-04-29 19:43:06 -04:00
}
2022-04-10 19:12:51 -04:00
#[ test ]
fn check ( ) {
let r = flags_from_vec ( svec! [ " deno " , " check " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Check ( CheckFlags {
files : svec ! [ " script.ts " ] ,
} ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2022-04-10 19:12:51 -04:00
.. Flags ::default ( )
}
) ;
2022-12-07 13:33:26 -05:00
for all_flag in [ " --remote " , " --all " ] {
let r = flags_from_vec ( svec! [ " deno " , " check " , all_flag , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Check ( CheckFlags {
files : svec ! [ " script.ts " ] ,
} ) ,
type_check_mode : TypeCheckMode ::All ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" check " ,
all_flag ,
" --no-remote " ,
" script.ts "
] ) ;
2023-03-26 00:06:18 -04:00
assert_eq! (
r . unwrap_err ( ) . kind ( ) ,
clap ::error ::ErrorKind ::ArgumentConflict
) ;
2022-12-07 13:33:26 -05:00
}
2022-04-10 19:12:51 -04:00
}
2019-04-29 19:43:06 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn info ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " info " , " script.ts " ] ) ;
2019-11-26 11:06:32 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-07-08 10:50:12 -04:00
json : false ,
file : Some ( " script.ts " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-07-08 10:50:12 -04:00
.. Flags ::default ( )
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " info " , " --reload " , " script.ts " ] ) ;
2020-08-12 06:58:50 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-08-12 06:58:50 -04:00
json : false ,
file : Some ( " script.ts " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-08-12 06:58:50 -04:00
reload : true ,
.. Flags ::default ( )
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " info " , " --json " , " script.ts " ] ) ;
2020-07-08 10:50:12 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-07-08 10:50:12 -04:00
json : true ,
2020-02-04 14:24:33 -05:00
file : Some ( " script.ts " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-11-26 11:06:32 -05:00
}
) ;
2019-08-11 20:43:01 -04:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " info " ] ) ;
2019-11-26 11:06:32 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-07-08 10:50:12 -04:00
json : false ,
file : None
2021-09-03 19:33:35 -04:00
} ) ,
2020-07-08 10:50:12 -04:00
.. Flags ::default ( )
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " info " , " --json " ] ) ;
2020-07-08 10:50:12 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-07-08 10:50:12 -04:00
json : true ,
file : None
2021-09-03 19:33:35 -04:00
} ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-11-26 11:06:32 -05:00
}
) ;
2022-06-13 14:09:04 -04:00
2023-03-13 17:04:00 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" info " ,
" --no-npm " ,
" --no-remote " ,
" --config " ,
" tsconfig.json "
] ) ;
2022-06-13 14:09:04 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Info ( InfoFlags {
json : false ,
file : None
} ) ,
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2023-03-13 17:04:00 -04:00
no_npm : true ,
no_remote : true ,
2022-06-13 14:09:04 -04:00
.. Flags ::default ( )
}
) ;
2019-04-21 11:34:18 -04:00
}
2019-04-29 10:58:31 -04:00
2019-05-03 16:24:09 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn tsconfig ( ) {
2021-01-07 13:06:08 -05:00
let r =
flags_from_vec ( svec! [ " deno " , " run " , " -c " , " tsconfig.json " , " script.ts " ] ) ;
2019-05-03 17:15:16 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-03 17:15:16 -04:00
}
) ;
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn eval ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " eval " , " 'console.log( \" hello \" )' " ] ) ;
2019-05-03 17:15:16 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Eval ( EvalFlags {
2020-05-21 10:35:36 -04:00
print : false ,
2020-02-04 14:24:33 -05:00
code : " 'console.log( \" hello \" )' " . to_string ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2020-02-28 09:17:56 -05:00
.. Flags ::default ( )
}
) ;
}
2020-05-21 10:35:36 -04:00
#[ test ]
fn eval_p ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " eval " , " -p " , " 1+2 " ] ) ;
2020-05-21 10:35:36 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Eval ( EvalFlags {
2020-05-21 10:35:36 -04:00
print : true ,
code : " 1+2 " . to_string ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2020-05-21 10:35:36 -04:00
.. Flags ::default ( )
}
) ;
}
2020-02-28 09:17:56 -05:00
#[ test ]
fn eval_typescript ( ) {
2024-09-02 11:27:26 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" eval " ,
" --ext=ts " ,
" 'console.log( \" hello \" )' "
] ) ;
2020-02-28 09:17:56 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Eval ( EvalFlags {
2020-05-21 10:35:36 -04:00
print : false ,
2020-02-28 09:17:56 -05:00
code : " 'console.log( \" hello \" )' " . to_string ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2023-03-22 10:15:53 -04:00
ext : Some ( " ts " . to_string ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-03 17:15:16 -04:00
}
) ;
}
2020-01-26 09:49:34 -05:00
#[ test ]
2020-09-18 13:09:11 -04:00
fn eval_with_flags ( ) {
#[ rustfmt::skip ]
2024-08-27 23:23:51 -04:00
let r = flags_from_vec ( svec! [ " deno " , " eval " , " --import-map " , " import_map.json " , " --no-remote " , " --config " , " tsconfig.json " , " --no-check " , " --reload " , " --lock " , " lock.json " , " --cert " , " example.crt " , " --cached-only " , " --location " , " https:foo " , " --v8-flags=--help " , " --seed " , " 1 " , " --inspect=127.0.0.1:9229 " , " --env=.example.env " , " 42 " ] ) ;
2020-01-26 09:49:34 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Eval ( EvalFlags {
2020-05-21 10:35:36 -04:00
print : false ,
2020-02-04 14:24:33 -05:00
code : " 42 " . to_string ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-09-18 13:09:11 -04:00
import_map_path : Some ( " import_map.json " . to_string ( ) ) ,
no_remote : true ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2020-09-18 13:09:11 -04:00
reload : true ,
2024-03-14 19:53:46 -04:00
lock : Some ( String ::from ( " lock.json " ) ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_string ( ) ) ) ,
2020-09-18 13:09:11 -04:00
cached_only : true ,
2021-01-07 13:06:08 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --help " , " --random-seed=1 " ] ,
2020-09-18 13:09:11 -04:00
seed : Some ( 1 ) ,
inspect : Some ( " 127.0.0.1:9229 " . parse ( ) . unwrap ( ) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .example.env " . to_owned ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2020-01-26 09:49:34 -05:00
}
) ;
}
2020-11-29 21:10:21 -05:00
#[ test ]
fn eval_args ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-11-29 21:10:21 -05:00
" deno " ,
" eval " ,
" console.log(Deno.args) " ,
" arg1 " ,
" arg2 "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Eval ( EvalFlags {
2020-11-29 21:10:21 -05:00
print : false ,
code : " console.log(Deno.args) " . to_string ( ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-11-29 21:10:21 -05:00
argv : svec ! [ " arg1 " , " arg2 " ] ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2020-11-29 21:10:21 -05:00
.. Flags ::default ( )
}
) ;
}
2019-05-03 17:15:16 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn repl ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " ] ) ;
2019-05-03 17:15:16 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2022-04-20 08:16:37 -04:00
subcommand : DenoSubcommand ::Repl ( ReplFlags {
eval_files : None ,
2022-12-07 14:21:18 -05:00
eval : None ,
is_default_command : true ,
2022-04-20 08:16:37 -04:00
} ) ,
2021-08-10 07:19:45 -04:00
unsafely_ignore_certificate_errors : None ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
deny_env : None ,
allow_run : Some ( vec! [ ] ) ,
deny_run : None ,
allow_read : Some ( vec! [ ] ) ,
deny_read : None ,
allow_sys : Some ( vec! [ ] ) ,
deny_sys : None ,
allow_write : Some ( vec! [ ] ) ,
deny_write : None ,
allow_ffi : Some ( vec! [ ] ) ,
deny_ffi : None ,
.. Default ::default ( )
} ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-03 17:15:16 -04:00
}
) ;
}
2023-11-10 12:41:24 -05:00
#[ test ]
fn repl_strace_ops ( ) {
// Lightly test this undocumented flag
let r = flags_from_vec ( svec! [ " deno " , " repl " , " --strace-ops " ] ) ;
assert_eq! ( r . unwrap ( ) . strace_ops , Some ( vec! [ ] ) ) ;
let r =
flags_from_vec ( svec! [ " deno " , " repl " , " --strace-ops=http,websocket " ] ) ;
assert_eq! (
r . unwrap ( ) . strace_ops ,
Some ( vec! [ " http " . to_string ( ) , " websocket " . to_string ( ) ] )
) ;
}
2020-04-30 11:23:40 -04:00
#[ test ]
2020-09-18 13:09:11 -04:00
fn repl_with_flags ( ) {
#[ rustfmt::skip ]
2024-08-27 23:23:51 -04:00
let r = flags_from_vec ( svec! [ " deno " , " repl " , " -A " , " --import-map " , " import_map.json " , " --no-remote " , " --config " , " tsconfig.json " , " --no-check " , " --reload " , " --lock " , " lock.json " , " --cert " , " example.crt " , " --cached-only " , " --location " , " https:foo " , " --v8-flags=--help " , " --seed " , " 1 " , " --inspect=127.0.0.1:9229 " , " --unsafely-ignore-certificate-errors " , " --env=.example.env " ] ) ;
2020-04-30 11:23:40 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2022-04-20 08:16:37 -04:00
subcommand : DenoSubcommand ::Repl ( ReplFlags {
eval_files : None ,
2022-12-07 14:21:18 -05:00
eval : None ,
is_default_command : false ,
2022-04-20 08:16:37 -04:00
} ) ,
2020-09-18 13:09:11 -04:00
import_map_path : Some ( " import_map.json " . to_string ( ) ) ,
no_remote : true ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2020-09-18 13:09:11 -04:00
reload : true ,
2024-03-14 19:53:46 -04:00
lock : Some ( String ::from ( " lock.json " ) ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_string ( ) ) ) ,
2020-09-18 13:09:11 -04:00
cached_only : true ,
2021-01-07 13:06:08 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --help " , " --random-seed=1 " ] ,
2020-09-18 13:09:11 -04:00
seed : Some ( 1 ) ,
inspect : Some ( " 127.0.0.1:9229 " . parse ( ) . unwrap ( ) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_all : true ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .example.env " . to_owned ( ) ) ,
2021-12-10 09:47:55 -05:00
unsafely_ignore_certificate_errors : Some ( vec! [ ] ) ,
2020-04-30 11:23:40 -04:00
.. Flags ::default ( )
}
) ;
}
2021-08-06 17:30:28 -04:00
#[ test ]
fn repl_with_eval_flag ( ) {
#[ rustfmt::skip ]
2022-12-07 14:21:18 -05:00
let r = flags_from_vec ( svec! [ " deno " , " repl " , " --allow-write " , " --eval " , " console.log('hello'); " ] ) ;
2021-08-06 17:30:28 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Repl ( ReplFlags {
2022-04-20 08:16:37 -04:00
eval_files : None ,
2021-08-06 17:30:28 -04:00
eval : Some ( " console.log('hello'); " . to_string ( ) ) ,
2022-12-07 14:21:18 -05:00
is_default_command : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_write : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2021-08-06 17:30:28 -04:00
.. Flags ::default ( )
}
) ;
}
2022-04-20 08:16:37 -04:00
#[ test ]
fn repl_with_eval_file_flag ( ) {
#[ rustfmt::skip ]
let r = flags_from_vec ( svec! [ " deno " , " repl " , " --eval-file=./a.js,./b.ts,https://examples.deno.land/hello-world.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Repl ( ReplFlags {
eval_files : Some ( vec! [
" ./a.js " . to_string ( ) ,
" ./b.ts " . to_string ( ) ,
" https://examples.deno.land/hello-world.ts " . to_string ( )
] ) ,
eval : None ,
2022-12-07 14:21:18 -05:00
is_default_command : false ,
2022-04-20 08:16:37 -04:00
} ) ,
type_check_mode : TypeCheckMode ::None ,
.. Flags ::default ( )
}
) ;
}
2019-05-08 19:20:30 -04:00
#[ test ]
2020-06-13 13:09:39 -04:00
fn allow_read_allowlist ( ) {
2022-04-01 11:15:37 -04:00
use test_util ::TempDir ;
let temp_dir_guard = TempDir ::new ( ) ;
2024-03-14 19:53:46 -04:00
let temp_dir = temp_dir_guard . path ( ) . to_string ( ) ;
2019-05-09 12:20:34 -04:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-05-08 19:20:30 -04:00
" deno " ,
" run " ,
2024-03-14 19:53:46 -04:00
format! ( " --allow-read=., {} " , temp_dir ) ,
2019-05-08 19:20:30 -04:00
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_read : Some ( vec! [ String ::from ( " . " ) , temp_dir ] ) ,
.. Default ::default ( )
} ,
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-08 19:20:30 -04:00
}
) ;
}
2019-06-09 09:08:20 -04:00
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_read_denylist ( ) {
use test_util ::TempDir ;
let temp_dir_guard = TempDir ::new ( ) ;
2024-03-14 19:53:46 -04:00
let temp_dir = temp_dir_guard . path ( ) . to_string ( ) ;
2023-08-03 07:19:19 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2024-03-14 19:53:46 -04:00
format! ( " --deny-read=., {} " , temp_dir ) ,
2023-08-03 07:19:19 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_read : Some ( vec! [ String ::from ( " . " ) , temp_dir ] ) ,
.. Default ::default ( )
} ,
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2019-05-08 19:20:30 -04:00
#[ test ]
2020-06-13 13:09:39 -04:00
fn allow_write_allowlist ( ) {
2022-04-01 11:15:37 -04:00
use test_util ::TempDir ;
let temp_dir_guard = TempDir ::new ( ) ;
2024-03-14 19:53:46 -04:00
let temp_dir = temp_dir_guard . path ( ) . to_string ( ) ;
2019-05-09 12:20:34 -04:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-05-08 19:20:30 -04:00
" deno " ,
" run " ,
2024-03-14 19:53:46 -04:00
format! ( " --allow-write=., {} " , temp_dir ) ,
2019-05-08 19:20:30 -04:00
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_write : Some ( vec! [ String ::from ( " . " ) , temp_dir ] ) ,
.. Default ::default ( )
} ,
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-08 19:20:30 -04:00
}
) ;
}
2019-06-09 09:08:20 -04:00
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_write_denylist ( ) {
use test_util ::TempDir ;
let temp_dir_guard = TempDir ::new ( ) ;
2024-03-14 19:53:46 -04:00
let temp_dir = temp_dir_guard . path ( ) . to_string ( ) ;
2023-08-03 07:19:19 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2024-03-14 19:53:46 -04:00
format! ( " --deny-write=., {} " , temp_dir ) ,
2023-08-03 07:19:19 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_write : Some ( vec! [ String ::from ( " . " ) , temp_dir ] ) ,
.. Default ::default ( )
} ,
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2019-05-08 19:20:30 -04:00
#[ test ]
2020-06-13 13:09:39 -04:00
fn allow_net_allowlist ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-05-08 19:20:30 -04:00
" deno " ,
" run " ,
" --allow-net=127.0.0.1 " ,
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( svec! [ " 127.0.0.1 " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-05-08 19:20:30 -04:00
}
) ;
}
2019-06-01 08:54:32 -04:00
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_net_denylist ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --deny-net=127.0.0.1 " , " script.ts " ] ) ;
2023-08-03 07:19:19 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_net : Some ( svec! [ " 127.0.0.1 " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2021-04-13 07:25:21 -04:00
#[ test ]
fn allow_env_allowlist ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-env=HOME " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_env : Some ( svec! [ " HOME " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-04-13 07:25:21 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_env_denylist ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --deny-env=HOME " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_env : Some ( svec! [ " HOME " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2021-04-13 07:25:21 -04:00
#[ test ]
fn allow_env_allowlist_multiple ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --allow-env=HOME,PATH " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_env : Some ( svec! [ " HOME " , " PATH " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-04-13 07:25:21 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_env_denylist_multiple ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --deny-env=HOME,PATH " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_env : Some ( svec! [ " HOME " , " PATH " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2021-04-13 07:25:21 -04:00
#[ test ]
fn allow_env_allowlist_validator ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-env=HOME " , " script.ts " ] ) ;
assert! ( r . is_ok ( ) ) ;
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --allow-env=H=ME " , " script.ts " ] ) ;
2021-04-13 07:25:21 -04:00
assert! ( r . is_err ( ) ) ;
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-env=H \0 ME " , " script.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_env_denylist_validator ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --deny-env=HOME " , " script.ts " ] ) ;
assert! ( r . is_ok ( ) ) ;
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --deny-env=H=ME " , " script.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --deny-env=H \0 ME " , " script.ts " ] ) ;
2023-08-03 07:19:19 -04:00
assert! ( r . is_err ( ) ) ;
}
2022-09-28 08:46:50 -04:00
#[ test ]
fn allow_sys ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --allow-sys " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_sys : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-09-28 08:46:50 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_sys ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --deny-sys " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_sys : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2022-09-28 08:46:50 -04:00
#[ test ]
fn allow_sys_allowlist ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-sys=hostname " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_sys : Some ( svec! [ " hostname " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-09-28 08:46:50 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_sys_denylist ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --deny-sys=hostname " , " script.ts " ] ) ;
2023-08-03 07:19:19 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_sys : Some ( svec! [ " hostname " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2022-09-28 08:46:50 -04:00
#[ test ]
fn allow_sys_allowlist_multiple ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --allow-sys=hostname,osRelease " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_sys : Some ( svec! [ " hostname " , " osRelease " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-09-28 08:46:50 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_sys_denylist_multiple ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --deny-sys=hostname,osRelease " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_sys : Some ( svec! [ " hostname " , " osRelease " ] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2022-09-28 08:46:50 -04:00
#[ test ]
fn allow_sys_allowlist_validator ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-sys=hostname " , " script.ts " ] ) ;
assert! ( r . is_ok ( ) ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --allow-sys=hostname,osRelease " ,
" script.ts "
] ) ;
assert! ( r . is_ok ( ) ) ;
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --allow-sys=foo " , " script.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --allow-sys=hostname,foo " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) ) ;
}
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_sys_denylist_validator ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --deny-sys=hostname " , " script.ts " ] ) ;
assert! ( r . is_ok ( ) ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --deny-sys=hostname,osRelease " ,
" script.ts "
] ) ;
assert! ( r . is_ok ( ) ) ;
let r = flags_from_vec ( svec! [ " deno " , " run " , " --deny-sys=foo " , " script.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --deny-sys=hostname,foo " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) ) ;
}
2022-09-06 12:30:42 -04:00
#[ test ]
fn reload_validator ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=http://deno.land/ " ,
" script.ts "
] ) ;
assert! ( r . is_ok ( ) , " should accept valid urls " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=http://deno.land/a,http://deno.land/b " ,
" script.ts "
] ) ;
assert! ( r . is_ok ( ) , " should accept accept multiple valid urls " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=./relativeurl/ " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) , " Should reject relative urls that start with ./ " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=relativeurl/ " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) , " Should reject relative urls " ) ;
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --reload=/absolute " , " script.ts " ] ) ;
assert! ( r . is_err ( ) , " Should reject absolute urls " ) ;
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --reload=/ " , " script.ts " ] ) ;
2022-09-06 12:30:42 -04:00
assert! ( r . is_err ( ) , " Should reject absolute root url " ) ;
let r = flags_from_vec ( svec! [ " deno " , " run " , " --reload= " , " script.ts " ] ) ;
assert! ( r . is_err ( ) , " Should reject when nothing is provided " ) ;
let r = flags_from_vec ( svec! [ " deno " , " run " , " --reload=, " , " script.ts " ] ) ;
assert! ( r . is_err ( ) , " Should reject when a single comma is provided " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=,http://deno.land/a " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) , " Should reject a leading comma " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=http://deno.land/a, " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) , " Should reject a trailing comma " ) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --reload=http://deno.land/a,,http://deno.land/b " ,
" script.ts "
] ) ;
assert! ( r . is_err ( ) , " Should reject adjacent commas " ) ;
}
2019-06-09 09:08:20 -04:00
#[ test ]
2020-10-20 08:30:59 -04:00
fn run_import_map ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-06-09 09:08:20 -04:00
" deno " ,
" run " ,
2020-10-20 08:30:59 -04:00
" --import-map=import_map.json " ,
2019-06-09 09:08:20 -04:00
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-10-20 08:30:59 -04:00
import_map_path : Some ( " import_map.json " . to_owned ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-09 09:08:20 -04:00
}
) ;
2019-11-26 11:06:32 -05:00
}
2019-06-09 09:08:20 -04:00
2020-09-21 09:07:19 -04:00
#[ test ]
2020-10-20 08:30:59 -04:00
fn info_import_map ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-09-21 09:07:19 -04:00
" deno " ,
" info " ,
2020-10-20 08:30:59 -04:00
" --import-map=import_map.json " ,
2020-09-21 09:07:19 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-09-21 09:07:19 -04:00
file : Some ( " script.ts " . to_string ( ) ) ,
json : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-10-20 08:30:59 -04:00
import_map_path : Some ( " import_map.json " . to_owned ( ) ) ,
2020-09-21 09:07:19 -04:00
.. Flags ::default ( )
}
) ;
}
2019-11-26 11:06:32 -05:00
#[ test ]
2020-10-20 08:30:59 -04:00
fn cache_import_map ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-07-27 10:37:03 -04:00
" deno " ,
2020-04-07 11:24:47 -04:00
" cache " ,
2020-10-20 08:30:59 -04:00
" --import-map=import_map.json " ,
2019-07-27 10:37:03 -04:00
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Cache ( CacheFlags {
2020-02-04 14:24:33 -05:00
files : svec ! [ " script.ts " ] ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-10-20 08:30:59 -04:00
import_map_path : Some ( " import_map.json " . to_owned ( ) ) ,
2020-10-11 19:05:46 -04:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
2020-10-20 08:30:59 -04:00
fn doc_import_map ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-10-11 19:05:46 -04:00
" deno " ,
" doc " ,
2020-10-20 08:30:59 -04:00
" --import-map=import_map.json " ,
2020-10-11 19:05:46 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2023-10-30 18:58:57 -04:00
source_files : DocSourceFileFlag ::Paths ( vec! [ " script.ts " . to_owned ( ) ] ) ,
2020-10-11 19:05:46 -04:00
private : false ,
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-31 18:19:42 -04:00
lint : false ,
2020-10-11 19:05:46 -04:00
filter : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-10-20 08:30:59 -04:00
import_map_path : Some ( " import_map.json " . to_owned ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-07-27 10:37:03 -04:00
}
) ;
2019-06-09 09:08:20 -04:00
}
2019-06-11 10:34:39 -04:00
2023-11-01 11:21:13 -04:00
#[ test ]
2024-08-08 09:50:57 -04:00
fn run_env_default ( ) {
2023-11-01 11:21:13 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --env " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .env " . to_owned ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
2024-08-08 09:50:57 -04:00
#[ test ]
fn run_env_file_default ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --env-file " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
env_file : Some ( " .env " . to_owned ( ) ) ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
2024-04-17 10:19:55 -04:00
#[ test ]
fn run_no_code_cache ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --no-code-cache " , " script.ts " ] ) ;
2024-04-17 10:19:55 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2023-11-01 11:21:13 -04:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
2024-08-08 09:50:57 -04:00
fn run_env_defined ( ) {
2023-11-01 11:21:13 -04:00
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --env=.another_env " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .another_env " . to_owned ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-11-01 11:21:13 -04:00
.. Flags ::default ( )
}
) ;
}
2024-08-08 09:50:57 -04:00
#[ test ]
fn run_env_file_defined ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --env-file=.another_env " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
env_file : Some ( " .another_env " . to_owned ( ) ) ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
2020-01-31 16:07:37 -05:00
#[ test ]
2020-04-07 11:24:47 -04:00
fn cache_multiple ( ) {
2020-01-31 16:07:37 -05:00
let r =
2021-01-07 13:06:08 -05:00
flags_from_vec ( svec! [ " deno " , " cache " , " script.ts " , " script_two.ts " ] ) ;
2020-01-31 16:07:37 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Cache ( CacheFlags {
2020-02-04 14:24:33 -05:00
files : svec ! [ " script.ts " , " script_two.ts " ] ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2020-01-31 16:07:37 -05:00
}
) ;
}
2019-06-11 10:34:39 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn run_seed ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --seed " , " 250 " , " script.ts " ] ) ;
2019-06-11 10:34:39 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-11-27 14:47:35 -05:00
seed : Some ( 250_ u64 ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --random-seed=250 " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-11 10:34:39 -04:00
}
) ;
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn run_seed_with_v8_flags ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-06-11 10:34:39 -04:00
" deno " ,
2019-11-26 11:06:32 -05:00
" run " ,
2019-06-11 10:34:39 -04:00
" --seed " ,
" 250 " ,
" --v8-flags=--expose-gc " ,
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-11-27 14:47:35 -05:00
seed : Some ( 250_ u64 ) ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --expose-gc " , " --random-seed=250 " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-11 10:34:39 -04:00
}
) ;
2019-06-15 10:08:11 -04:00
}
#[ test ]
2019-11-26 11:06:32 -05:00
fn install ( ) {
2024-08-30 13:58:58 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" install " ,
" -g " ,
" jsr:@std/http/file-server "
] ) ;
2019-06-15 10:08:11 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Install ( InstallFlags {
2024-04-04 10:40:54 -04:00
kind : InstallKind ::Global ( InstallFlagsGlobal {
name : None ,
2024-04-10 17:26:35 -04:00
module_url : " jsr:@std/http/file-server " . to_string ( ) ,
2024-04-04 10:40:54 -04:00
args : vec ! [ ] ,
root : None ,
force : false ,
} ) ,
2024-08-30 13:58:58 -04:00
global : true ,
2024-03-27 18:45:57 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" install " ,
" -g " ,
2024-04-10 17:26:35 -04:00
" jsr:@std/http/file-server "
2024-03-27 18:45:57 -04:00
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Install ( InstallFlags {
2024-04-04 10:40:54 -04:00
kind : InstallKind ::Global ( InstallFlagsGlobal {
name : None ,
2024-04-10 17:26:35 -04:00
module_url : " jsr:@std/http/file-server " . to_string ( ) ,
2024-04-04 10:40:54 -04:00
args : vec ! [ ] ,
root : None ,
force : false ,
} ) ,
2024-03-27 18:45:57 -04:00
global : true ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-15 10:08:11 -04:00
}
) ;
2019-11-26 11:06:32 -05:00
}
2019-06-15 10:08:11 -04:00
2019-11-26 11:06:32 -05:00
#[ test ]
2020-10-19 15:19:20 -04:00
fn install_with_flags ( ) {
#[ rustfmt::skip ]
2024-08-30 13:58:58 -04:00
let r = flags_from_vec ( svec! [ " deno " , " install " , " --global " , " --import-map " , " import_map.json " , " --no-remote " , " --config " , " tsconfig.json " , " --no-check " , " --unsafely-ignore-certificate-errors " , " --reload " , " --lock " , " lock.json " , " --cert " , " example.crt " , " --cached-only " , " --allow-read " , " --allow-net " , " --v8-flags=--help " , " --seed " , " 1 " , " --inspect=127.0.0.1:9229 " , " --name " , " file_server " , " --root " , " /foo " , " --force " , " --env=.example.env " , " jsr:@std/http/file-server " , " foo " , " bar " ] ) ;
2019-06-20 14:25:13 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Install ( InstallFlags {
2024-04-04 10:40:54 -04:00
kind : InstallKind ::Global ( InstallFlagsGlobal {
name : Some ( " file_server " . to_string ( ) ) ,
2024-04-10 17:26:35 -04:00
module_url : " jsr:@std/http/file-server " . to_string ( ) ,
2024-04-04 10:40:54 -04:00
args : svec ! [ " foo " , " bar " ] ,
root : Some ( " /foo " . to_string ( ) ) ,
force : true ,
} ) ,
2024-08-30 13:58:58 -04:00
global : true ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-10-19 15:19:20 -04:00
import_map_path : Some ( " import_map.json " . to_string ( ) ) ,
no_remote : true ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2020-10-19 15:19:20 -04:00
reload : true ,
2024-03-14 19:53:46 -04:00
lock : Some ( String ::from ( " lock.json " ) ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_string ( ) ) ) ,
2020-10-19 15:19:20 -04:00
cached_only : true ,
2020-12-06 12:19:21 -05:00
v8_flags : svec ! [ " --help " , " --random-seed=1 " ] ,
2020-10-19 15:19:20 -04:00
seed : Some ( 1 ) ,
inspect : Some ( " 127.0.0.1:9229 " . parse ( ) . unwrap ( ) ) ,
2021-08-10 07:19:45 -04:00
unsafely_ignore_certificate_errors : Some ( vec! [ ] ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .example.env " . to_owned ( ) ) ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-20 14:25:13 -04:00
}
) ;
2019-06-11 10:34:39 -04:00
}
2019-06-22 12:02:51 -04:00
2023-01-05 21:09:39 -05:00
#[ test ]
fn uninstall ( ) {
let r = flags_from_vec ( svec! [ " deno " , " uninstall " , " file_server " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Uninstall ( UninstallFlags {
2024-04-04 10:40:54 -04:00
kind : UninstallKind ::Global ( UninstallFlagsGlobal {
name : " file_server " . to_string ( ) ,
root : None ,
} ) ,
2024-03-27 18:45:57 -04:00
global : false ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " uninstall " , " -g " , " file_server " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Uninstall ( UninstallFlags {
2024-04-04 10:40:54 -04:00
kind : UninstallKind ::Global ( UninstallFlagsGlobal {
name : " file_server " . to_string ( ) ,
root : None ,
} ) ,
2024-03-27 18:45:57 -04:00
global : true ,
2023-01-05 21:09:39 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn uninstall_with_help_flag ( ) {
let r = flags_from_vec ( svec! [ " deno " , " uninstall " , " --help " ] ) ;
2024-08-18 18:39:53 -04:00
assert! ( r . is_ok ( ) ) ;
2023-01-05 21:09:39 -05:00
}
2019-06-22 12:02:51 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn log_level ( ) {
2021-01-07 13:06:08 -05:00
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --log-level=debug " , " script.ts " ] ) ;
2019-06-22 12:02:51 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2019-06-22 12:02:51 -04:00
log_level : Some ( Level ::Debug ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-22 12:02:51 -04:00
}
) ;
}
2019-06-26 06:02:13 -04:00
2020-03-10 08:26:17 -04:00
#[ test ]
fn quiet ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " -q " , " script.ts " ] ) ;
2020-03-10 08:26:17 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2020-03-10 08:26:17 -04:00
log_level : Some ( Level ::Error ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-03-10 08:26:17 -04:00
.. Flags ::default ( )
}
) ;
}
2019-06-26 06:02:13 -04:00
#[ test ]
2019-11-26 11:06:32 -05:00
fn completions ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " completions " , " zsh " ] ) . unwrap ( ) ;
2020-02-04 14:24:33 -05:00
match r . subcommand {
2021-09-03 19:33:35 -04:00
DenoSubcommand ::Completions ( CompletionsFlags { buf } ) = > {
assert! ( ! buf . is_empty ( ) )
}
2020-02-04 14:24:33 -05:00
_ = > unreachable! ( ) ,
}
2019-06-26 06:02:13 -04:00
}
2019-06-29 18:32:54 -04:00
#[ test ]
2020-08-28 19:20:57 -04:00
fn run_with_args ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-08-28 19:20:57 -04:00
" deno " ,
" run " ,
" script.ts " ,
" --allow-read " ,
" --allow-net "
] ) ;
2019-06-29 18:32:54 -04:00
assert_eq! (
2020-08-28 19:20:57 -04:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-08-28 19:20:57 -04:00
argv : svec ! [ " --allow-read " , " --allow-net " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-29 18:32:54 -04:00
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-06-29 18:32:54 -04:00
" deno " ,
" run " ,
2021-01-07 13:06:08 -05:00
" --location " ,
" https:foo " ,
2019-11-26 11:06:32 -05:00
" --allow-read " ,
2019-06-29 18:32:54 -04:00
" script.ts " ,
" --allow-net " ,
" -r " ,
" --help " ,
" --foo " ,
" bar "
] ) ;
assert_eq! (
2020-08-28 19:20:57 -04:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2021-01-07 13:06:08 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_read : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2020-08-28 19:20:57 -04:00
argv : svec ! [ " --allow-net " , " -r " , " --help " , " --foo " , " bar " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-06-29 18:32:54 -04:00
}
) ;
2020-08-28 19:20:57 -04:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " script.ts " , " foo " , " bar " ] ) ;
2020-08-28 19:20:57 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-08-28 19:20:57 -04:00
argv : svec ! [ " foo " , " bar " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-08-28 19:20:57 -04:00
.. Flags ::default ( )
}
) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " script.ts " , " - " ] ) ;
2020-08-28 19:20:57 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-08-28 19:20:57 -04:00
argv : svec ! [ " - " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-08-28 19:20:57 -04:00
.. Flags ::default ( )
}
) ;
let r =
2021-01-07 13:06:08 -05:00
flags_from_vec ( svec! [ " deno " , " run " , " script.ts " , " - " , " foo " , " bar " ] ) ;
2020-08-28 19:20:57 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2020-08-28 19:20:57 -04:00
argv : svec ! [ " - " , " foo " , " bar " ] ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-08-28 19:20:57 -04:00
.. Flags ::default ( )
}
) ;
}
2019-07-20 09:19:06 -04:00
2020-07-08 05:26:39 -04:00
#[ test ]
fn no_check ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --no-check " , " script.ts " ] ) ;
2020-07-08 05:26:39 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-11-29 17:23:30 -05:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn no_check_remote ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " run " , " --no-check=remote " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::Local ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-07-08 05:26:39 -04:00
.. Flags ::default ( )
}
) ;
}
2021-08-09 10:53:21 -04:00
#[ test ]
2021-12-10 09:47:55 -05:00
fn repl_with_unsafely_ignore_certificate_errors ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" repl " ,
" --eval " ,
" console.log('hello'); " ,
" --unsafely-ignore-certificate-errors "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Repl ( ReplFlags {
2022-04-20 08:16:37 -04:00
eval_files : None ,
2021-12-10 09:47:55 -05:00
eval : Some ( " console.log('hello'); " . to_string ( ) ) ,
2022-12-07 14:21:18 -05:00
is_default_command : false ,
2021-12-10 09:47:55 -05:00
} ) ,
unsafely_ignore_certificate_errors : Some ( vec! [ ] ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2021-12-10 09:47:55 -05:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn run_with_unsafely_ignore_certificate_errors ( ) {
2021-08-09 10:53:21 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2021-08-10 07:19:45 -04:00
" --unsafely-ignore-certificate-errors " ,
2021-08-09 10:53:21 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2021-08-10 07:19:45 -04:00
unsafely_ignore_certificate_errors : Some ( vec! [ ] ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-08-09 10:53:21 -04:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
2021-12-10 09:47:55 -05:00
fn run_with_unsafely_treat_insecure_origin_as_secure_with_ipv6_address ( ) {
2021-08-09 10:53:21 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2024-07-05 18:45:06 -04:00
" --unsafely-ignore-certificate-errors=deno.land,localhost,[::],127.0.0.1,[::1],1.2.3.4 " ,
2021-08-09 10:53:21 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2021-08-10 07:19:45 -04:00
unsafely_ignore_certificate_errors : Some ( svec! [
2021-08-09 10:53:21 -04:00
" deno.land " ,
" localhost " ,
2024-07-05 18:45:06 -04:00
" [::] " ,
2021-08-09 10:53:21 -04:00
" 127.0.0.1 " ,
" [::1] " ,
" 1.2.3.4 "
] ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-08-09 10:53:21 -04:00
.. Flags ::default ( )
}
) ;
}
2021-12-10 09:47:55 -05:00
#[ test ]
fn repl_with_unsafely_treat_insecure_origin_as_secure_with_ipv6_address ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" repl " ,
2024-07-05 18:45:06 -04:00
" --unsafely-ignore-certificate-errors=deno.land,localhost,[::],127.0.0.1,[::1],1.2.3.4 " ] ) ;
2021-12-10 09:47:55 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2022-04-20 08:16:37 -04:00
subcommand : DenoSubcommand ::Repl ( ReplFlags {
eval_files : None ,
2022-12-07 14:21:18 -05:00
eval : None ,
is_default_command : false ,
2022-04-20 08:16:37 -04:00
} ) ,
2021-12-10 09:47:55 -05:00
unsafely_ignore_certificate_errors : Some ( svec! [
" deno.land " ,
" localhost " ,
2024-07-05 18:45:06 -04:00
" [::] " ,
2021-12-10 09:47:55 -05:00
" 127.0.0.1 " ,
" [::1] " ,
" 1.2.3.4 "
] ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2021-12-10 09:47:55 -05:00
.. Flags ::default ( )
}
) ;
}
2019-07-20 09:19:06 -04:00
#[ test ]
2019-12-03 17:48:53 -05:00
fn no_remote ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --no-remote " , " script.ts " ] ) ;
2019-12-03 17:48:53 -05:00
assert_eq! (
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2019-12-03 17:48:53 -05:00
no_remote : true ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-12-03 17:48:53 -05:00
}
) ;
}
2022-09-07 09:33:51 -04:00
#[ test ]
fn no_npm ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --no-npm " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-09-07 09:33:51 -04:00
no_npm : true ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-09-07 09:33:51 -04:00
.. Flags ::default ( )
}
) ;
}
2022-09-22 11:17:02 -04:00
#[ test ]
fn local_npm ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --node-modules-dir " , " script.ts " ] ) ;
2022-09-22 11:17:02 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2024-08-30 13:58:58 -04:00
node_modules_dir : None ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-09-22 11:17:02 -04:00
.. Flags ::default ( )
}
) ;
}
2023-08-01 20:49:09 -04:00
#[ test ]
2023-08-06 21:56:56 -04:00
fn vendor_flag ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --vendor " , " script.ts " ] ) ;
2023-08-01 20:49:09 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2023-08-06 21:56:56 -04:00
vendor : Some ( true ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-01 20:49:09 -04:00
.. Flags ::default ( )
}
) ;
2023-08-06 21:56:56 -04:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --vendor=false " , " script.ts " ] ) ;
2023-08-01 20:49:09 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2023-08-06 21:56:56 -04:00
vendor : Some ( false ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-01 20:49:09 -04:00
.. Flags ::default ( )
}
) ;
}
2019-12-03 17:48:53 -05:00
#[ test ]
fn cached_only ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --cached-only " , " script.ts " ] ) ;
2019-07-20 09:19:06 -04:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2019-12-03 17:48:53 -05:00
cached_only : true ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-07-20 09:19:06 -04:00
}
) ;
}
2019-07-31 11:02:20 -04:00
2019-10-12 17:13:52 -04:00
#[ test ]
2020-06-13 13:09:39 -04:00
fn allow_net_allowlist_with_ports ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2019-10-12 17:13:52 -04:00
" deno " ,
2020-05-04 07:03:30 -04:00
" run " ,
2019-10-12 17:13:52 -04:00
" --allow-net=deno.land,:8000,:4545 " ,
" script.ts "
] ) ;
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( svec! [
" deno.land " ,
" 0.0.0.0:8000 " ,
" 127.0.0.1:8000 " ,
" localhost:8000 " ,
" 0.0.0.0:4545 " ,
" 127.0.0.1:4545 " ,
" localhost:4545 "
] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-02-26 05:52:15 -05:00
.. Flags ::default ( )
2019-10-12 17:13:52 -04:00
}
) ;
}
2019-11-03 10:39:27 -05:00
2023-08-03 07:19:19 -04:00
#[ test ]
fn deny_net_denylist_with_ports ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --deny-net=deno.land,:8000,:4545 " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_net : Some ( svec! [
" deno.land " ,
" 0.0.0.0:8000 " ,
" 127.0.0.1:8000 " ,
" localhost:8000 " ,
" 0.0.0.0:4545 " ,
" 127.0.0.1:4545 " ,
" localhost:4545 "
] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
2020-06-26 08:09:02 -04:00
#[ test ]
fn allow_net_allowlist_with_ipv6_address ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-06-26 08:09:02 -04:00
" deno " ,
" run " ,
2024-07-05 18:45:06 -04:00
" --allow-net=deno.land,deno.land:80,[::],127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080 " ,
2020-06-26 08:09:02 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( svec! [
" deno.land " ,
" deno.land:80 " ,
2024-07-05 18:45:06 -04:00
" [::] " ,
2024-05-06 19:21:58 -04:00
" 127.0.0.1 " ,
" [::1] " ,
" 1.2.3.4:5678 " ,
" 0.0.0.0:5678 " ,
" 127.0.0.1:5678 " ,
" localhost:5678 " ,
" [::1]:8080 "
] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2023-08-03 07:19:19 -04:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn deny_net_denylist_with_ipv6_address ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
2024-07-05 18:45:06 -04:00
" --deny-net=deno.land,deno.land:80,[::],127.0.0.1,[::1],1.2.3.4:5678,:5678,[::1]:8080 " ,
2023-08-03 07:19:19 -04:00
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
deny_net : Some ( svec! [
" deno.land " ,
" deno.land:80 " ,
2024-07-05 18:45:06 -04:00
" [::] " ,
2024-05-06 19:21:58 -04:00
" 127.0.0.1 " ,
" [::1] " ,
" 1.2.3.4:5678 " ,
" 0.0.0.0:5678 " ,
" 127.0.0.1:5678 " ,
" localhost:5678 " ,
" [::1]:8080 "
] ) ,
.. Default ::default ( )
} ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-06-26 08:09:02 -04:00
.. Flags ::default ( )
}
) ;
}
2023-01-09 07:29:43 -05:00
#[ test ]
fn test_no_colon_in_value_name ( ) {
2024-08-12 11:55:33 -04:00
let app =
runtime_args ( Command ::new ( " test_inspect_completion_value " ) , true , true ) ;
2023-01-09 07:29:43 -05:00
let inspect_args = app
. get_arguments ( )
. filter ( | arg | arg . get_id ( ) = = " inspect " )
. collect ::< Vec < _ > > ( ) ;
// The value_name cannot have a : otherwise it breaks shell completions for zsh.
let value_name = " HOST_AND_PORT " ;
let arg = inspect_args
. iter ( )
. any ( | v | v . get_value_names ( ) . unwrap ( ) = = [ value_name ] ) ;
assert_eq! ( arg , true ) ;
}
2019-11-26 11:06:32 -05:00
#[ test ]
2020-11-22 08:06:51 -05:00
fn test_with_flags ( ) {
#[ rustfmt::skip ]
2024-08-02 09:18:59 -04:00
let r = flags_from_vec ( svec! [ " deno " , " test " , " --unstable " , " --no-npm " , " --no-remote " , " --trace-leaks " , " --no-run " , " --filter " , " - foo " , " --coverage=cov " , " --clean " , " --location " , " https:foo " , " --allow-net " , " --permit-no-files " , " dir1/ " , " dir2/ " , " -- " , " arg1 " , " arg2 " ] ) ;
2019-11-13 11:21:17 -05:00
assert_eq! (
2019-11-26 11:06:32 -05:00
r . unwrap ( ) ,
2020-02-26 05:52:15 -05:00
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Test ( TestFlags {
2020-11-22 08:06:51 -05:00
no_run : true ,
2021-05-10 19:54:39 -04:00
doc : false ,
2021-07-12 06:55:42 -04:00
fail_fast : None ,
2020-11-22 08:06:51 -05:00
filter : Some ( " - foo " . to_string ( ) ) ,
2024-09-02 18:06:27 -04:00
permit_no_files : true ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " dir1/ " . to_string ( ) , " dir2/ " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2021-07-05 21:20:33 -04:00
shuffle : None ,
2023-01-07 15:22:09 -05:00
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : true ,
2023-06-15 13:09:37 -04:00
coverage_dir : Some ( " cov " . to_string ( ) ) ,
2024-05-22 23:04:12 -04:00
clean : true ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-01-22 12:37:28 -05:00
unstable_config : UnstableConfig {
legacy_flag_enabled : true ,
.. Default ::default ( )
} ,
2023-03-13 17:04:00 -04:00
no_npm : true ,
no_remote : true ,
2021-01-07 13:06:08 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
allow_net : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2020-10-25 20:25:43 -04:00
argv : svec ! [ " arg1 " , " arg2 " ] ,
.. Flags ::default ( )
}
) ;
}
2020-04-02 09:26:40 -04:00
#[ test ]
fn run_with_cafile ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-04-02 09:26:40 -04:00
" deno " ,
" run " ,
" --cert " ,
" example.crt " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_owned ( ) ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
}
2020-02-17 11:59:51 -05:00
2021-07-23 10:31:16 -04:00
#[ test ]
fn run_with_enable_testing_features ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --enable-testing-features-do-not-use " ,
" script.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2021-07-23 10:31:16 -04:00
enable_testing_features : true ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2021-07-23 10:31:16 -04:00
.. Flags ::default ( )
}
) ;
}
2021-07-12 06:55:42 -04:00
#[ test ]
fn test_with_fail_fast ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --fail-fast=3 " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Test ( TestFlags {
2021-07-12 06:55:42 -04:00
no_run : false ,
doc : false ,
2021-08-23 06:37:02 -04:00
fail_fast : Some ( NonZeroUsize ::new ( 3 ) . unwrap ( ) ) ,
2021-07-12 06:55:42 -04:00
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2021-07-12 06:55:42 -04:00
shuffle : None ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2021-07-12 06:55:42 -04:00
.. Flags ::default ( )
}
) ;
2021-08-23 06:37:02 -04:00
let r = flags_from_vec ( svec! [ " deno " , " test " , " --fail-fast=0 " ] ) ;
assert! ( r . is_err ( ) ) ;
2021-07-12 06:55:42 -04:00
}
2021-07-23 10:31:16 -04:00
#[ test ]
fn test_with_enable_testing_features ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" test " ,
" --enable-testing-features-do-not-use "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Test ( TestFlags {
2021-07-23 10:31:16 -04:00
no_run : false ,
doc : false ,
fail_fast : None ,
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2021-07-23 10:31:16 -04:00
shuffle : None ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2021-07-23 10:31:16 -04:00
enable_testing_features : true ,
.. Flags ::default ( )
}
) ;
}
2021-07-27 14:18:16 -04:00
2023-08-02 12:38:10 -04:00
#[ test ]
2023-08-02 22:05:34 -04:00
fn test_reporter ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --reporter=pretty " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
reporter : TestReporterConfig ::Pretty ,
.. Default ::default ( )
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-08-02 22:05:34 -04:00
type_check_mode : TypeCheckMode ::Local ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " test " , " --reporter=dot " ] ) ;
2023-08-02 12:38:10 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
reporter : TestReporterConfig ::Dot ,
2023-08-02 22:05:34 -04:00
.. Default ::default ( )
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-08-02 22:05:34 -04:00
type_check_mode : TypeCheckMode ::Local ,
log_level : Some ( Level ::Error ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " test " , " --reporter=junit " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
reporter : TestReporterConfig ::Junit ,
.. Default ::default ( )
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-08-02 22:05:34 -04:00
type_check_mode : TypeCheckMode ::Local ,
.. Flags ::default ( )
2023-08-25 19:19:23 -04:00
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " test " , " --reporter=tap " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
reporter : TestReporterConfig ::Tap ,
.. Default ::default ( )
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-08-25 19:19:23 -04:00
type_check_mode : TypeCheckMode ::Local ,
log_level : Some ( Level ::Error ) ,
.. Flags ::default ( )
2023-08-02 22:05:34 -04:00
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" test " ,
" --reporter=dot " ,
" --junit-path=report.xml "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
reporter : TestReporterConfig ::Dot ,
junit_path : Some ( " report.xml " . to_string ( ) ) ,
.. Default ::default ( )
2023-08-02 12:38:10 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-08-02 12:38:10 -04:00
type_check_mode : TypeCheckMode ::Local ,
log_level : Some ( Level ::Error ) ,
.. Flags ::default ( )
}
) ;
2023-08-02 22:05:34 -04:00
let r = flags_from_vec ( svec! [ " deno " , " test " , " --junit-path " ] ) ;
2023-08-02 12:38:10 -04:00
assert! ( r . is_err ( ) ) ;
}
2021-07-27 14:18:16 -04:00
#[ test ]
fn test_shuffle ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --shuffle=1 " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Test ( TestFlags {
2021-07-27 14:18:16 -04:00
no_run : false ,
doc : false ,
fail_fast : None ,
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2021-07-27 14:18:16 -04:00
shuffle : Some ( 1 ) ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2021-07-27 14:18:16 -04:00
.. Flags ::default ( )
}
) ;
}
2021-07-20 05:29:17 -04:00
#[ test ]
fn test_watch ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --watch " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Test ( TestFlags {
2021-07-20 05:29:17 -04:00
no_run : false ,
doc : false ,
fail_fast : None ,
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2021-07-20 05:29:17 -04:00
shuffle : None ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2023-01-07 15:22:09 -05:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-01-07 15:22:09 -05:00
type_check_mode : TypeCheckMode ::Local ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn test_watch_explicit_cwd ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --watch " , " ./ " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
no_run : false ,
doc : false ,
fail_fast : None ,
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2023-01-07 15:22:09 -05:00
shuffle : None ,
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " ./ " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2021-09-03 19:33:35 -04:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2021-07-20 05:29:17 -04:00
.. Flags ::default ( )
}
) ;
}
2022-01-31 11:39:39 -05:00
#[ test ]
fn test_watch_with_no_clear_screen ( ) {
let r =
flags_from_vec ( svec! [ " deno " , " test " , " --watch " , " --no-clear-screen " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
no_run : false ,
doc : false ,
fail_fast : None ,
filter : None ,
2024-09-02 18:06:27 -04:00
permit_no_files : false ,
2022-01-31 11:39:39 -05:00
shuffle : None ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
concurrent_jobs : None ,
2024-02-28 11:12:43 -05:00
trace_leaks : false ,
2023-06-15 13:09:37 -04:00
coverage_dir : None ,
2024-05-22 23:04:12 -04:00
clean : false ,
2024-08-19 13:09:51 -04:00
watch : Some ( WatchFlagsWithPaths {
2023-10-30 20:25:58 -04:00
hmr : false ,
2023-06-15 13:09:37 -04:00
no_clear_screen : true ,
2024-03-27 18:47:46 -04:00
exclude : vec ! [ ] ,
2024-08-19 13:09:51 -04:00
paths : vec ! [ ] ,
2023-06-15 13:09:37 -04:00
} ) ,
2023-08-02 12:38:10 -04:00
reporter : Default ::default ( ) ,
2023-08-02 22:05:34 -04:00
junit_path : None ,
2024-08-19 21:27:36 -04:00
hide_stacktraces : false ,
2022-01-31 11:39:39 -05:00
} ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2022-01-31 11:39:39 -05:00
.. Flags ::default ( )
2023-12-08 03:35:42 -05:00
}
) ;
}
2024-08-19 13:09:51 -04:00
#[ test ]
fn test_watch_with_paths ( ) {
let r = flags_from_vec ( svec! ( " deno " , " test " , " --watch=foo " ) ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " test " , " --watch=foo,bar " ] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) , String ::from ( " bar " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn test_watch_with_excluded_paths ( ) {
let r =
flags_from_vec ( svec! ( " deno " , " test " , " --watch " , " --watch-exclude=foo " , ) ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " foo " ) ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! (
" deno " ,
" test " ,
" --watch=foo " ,
" --watch-exclude=bar " ,
) ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " bar " ) ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" test " ,
" --watch " ,
" --watch-exclude=foo,bar " ,
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " foo " ) , String ::from ( " bar " ) ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" test " ,
" --watch=foo,bar " ,
" --watch-exclude=baz,qux " ,
] ) ;
let flags = r . unwrap ( ) ;
assert_eq! (
flags ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
watch : Some ( WatchFlagsWithPaths {
hmr : false ,
paths : vec ! [ String ::from ( " foo " ) , String ::from ( " bar " ) ] ,
no_clear_screen : false ,
exclude : vec ! [ String ::from ( " baz " ) , String ::from ( " qux " ) , ] ,
} ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
}
2023-12-08 03:35:42 -05:00
#[ test ]
fn test_coverage_default_dir ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --coverage " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
coverage_dir : Some ( " coverage " . to_string ( ) ) ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
2024-08-19 21:27:36 -04:00
no_prompt : true ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn test_hide_stacktraces ( ) {
let r = flags_from_vec ( svec! [ " deno " , " test " , " --hide-stacktraces " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Test ( TestFlags {
hide_stacktraces : true ,
.. TestFlags ::default ( )
} ) ,
type_check_mode : TypeCheckMode ::Local ,
permissions : PermissionFlags {
2024-05-06 19:21:58 -04:00
no_prompt : true ,
.. Default ::default ( )
} ,
2023-12-08 03:35:42 -05:00
.. Flags ::default ( )
2022-01-31 11:39:39 -05:00
}
) ;
}
2020-07-05 23:58:23 -04:00
#[ test ]
fn upgrade_with_ca_file ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --cert " , " example.crt " ] ) ;
2020-07-05 23:58:23 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Upgrade ( UpgradeFlags {
2020-07-05 23:58:23 -04:00
force : false ,
dry_run : false ,
2020-11-29 14:00:35 -05:00
canary : false ,
2024-08-12 14:32:53 -04:00
release_candidate : false ,
2020-07-05 23:58:23 -04:00
version : None ,
2020-07-06 18:21:26 -04:00
output : None ,
2024-08-19 11:05:10 -04:00
version_or_hash_or_channel : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_owned ( ) ) ) ,
2020-07-05 23:58:23 -04:00
.. Flags ::default ( )
}
) ;
}
2024-08-12 14:32:53 -04:00
#[ test ]
fn upgrade_release_candidate ( ) {
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --rc " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Upgrade ( UpgradeFlags {
force : false ,
dry_run : false ,
canary : false ,
release_candidate : true ,
version : None ,
output : None ,
2024-08-19 11:05:10 -04:00
version_or_hash_or_channel : None ,
2024-08-12 14:32:53 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --rc " , " --canary " ] ) ;
assert! ( r . is_err ( ) ) ;
let r = flags_from_vec ( svec! [ " deno " , " upgrade " , " --rc " , " --version " ] ) ;
assert! ( r . is_err ( ) ) ;
}
2020-04-02 09:26:40 -04:00
#[ test ]
2020-04-07 11:24:47 -04:00
fn cache_with_cafile ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-04-02 09:26:40 -04:00
" deno " ,
2020-04-07 11:24:47 -04:00
" cache " ,
2020-04-02 09:26:40 -04:00
" --cert " ,
" example.crt " ,
" script.ts " ,
" script_two.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Cache ( CacheFlags {
2020-04-02 09:26:40 -04:00
files : svec ! [ " script.ts " , " script_two.ts " ] ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_owned ( ) ) ) ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
}
2020-02-17 11:59:51 -05:00
2020-04-02 09:26:40 -04:00
#[ test ]
fn info_with_cafile ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-04-02 09:26:40 -04:00
" deno " ,
" info " ,
" --cert " ,
" example.crt " ,
" https://example.com "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Info ( InfoFlags {
2020-07-08 10:50:12 -04:00
json : false ,
2020-04-02 09:26:40 -04:00
file : Some ( " https://example.com " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_owned ( ) ) ) ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
}
2020-02-17 11:59:51 -05:00
2020-04-02 09:26:40 -04:00
#[ test ]
fn doc ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " doc " , " --json " , " path/to/module.ts " ] ) ;
2020-04-02 09:26:40 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2020-07-12 08:16:33 -04:00
private : false ,
2020-04-02 09:26:40 -04:00
json : true ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-31 18:19:42 -04:00
lint : false ,
2023-11-01 11:25:05 -04:00
source_files : DocSourceFileFlag ::Paths ( svec! [ " path/to/module.ts " ] ) ,
filter : None ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " doc " , " --html " , " path/to/module.ts " ] ) ;
2024-04-24 16:34:21 -04:00
assert! ( r . is_ok ( ) ) ;
2023-11-01 11:25:05 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" --html " ,
" --name=My library " ,
" path/to/module.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Doc ( DocFlags {
private : false ,
json : false ,
lint : false ,
html : Some ( DocHtmlFlag {
2024-04-24 16:34:21 -04:00
name : Some ( " My library " . to_string ( ) ) ,
2024-06-28 08:03:51 -04:00
category_docs_path : None ,
symbol_redirect_map_path : None ,
default_symbol_map_path : None ,
strip_trailing_html : false ,
2024-03-14 19:53:46 -04:00
output : String ::from ( " ./docs/ " ) ,
2023-11-01 11:25:05 -04:00
} ) ,
source_files : DocSourceFileFlag ::Paths ( svec! [ " path/to/module.ts " ] ) ,
filter : None ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" --html " ,
" --name=My library " ,
" --lint " ,
" --output=./foo " ,
" path/to/module.ts "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Doc ( DocFlags {
private : false ,
json : false ,
html : Some ( DocHtmlFlag {
2024-04-24 16:34:21 -04:00
name : Some ( " My library " . to_string ( ) ) ,
2024-06-28 08:03:51 -04:00
category_docs_path : None ,
symbol_redirect_map_path : None ,
default_symbol_map_path : None ,
strip_trailing_html : false ,
2024-03-14 19:53:46 -04:00
output : String ::from ( " ./foo " ) ,
2023-11-01 11:25:05 -04:00
} ) ,
lint : true ,
source_files : DocSourceFileFlag ::Paths ( svec! [ " path/to/module.ts " ] ) ,
2020-04-02 09:26:40 -04:00
filter : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
2020-03-28 14:16:57 -04:00
2023-11-03 13:06:18 -04:00
let r =
flags_from_vec ( svec! [ " deno " , " doc " , " --html " , " --name=My library " , ] ) ;
assert! ( r . is_err ( ) ) ;
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-04-02 09:26:40 -04:00
" deno " ,
" doc " ,
2023-10-30 18:58:57 -04:00
" --filter " ,
" SomeClass.someField " ,
2020-04-02 09:26:40 -04:00
" path/to/module.ts " ,
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2020-07-12 08:16:33 -04:00
private : false ,
2020-04-02 09:26:40 -04:00
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-31 18:19:42 -04:00
lint : false ,
2023-10-30 18:58:57 -04:00
source_files : DocSourceFileFlag ::Paths ( vec! [
" path/to/module.ts " . to_string ( )
] ) ,
2020-04-02 09:26:40 -04:00
filter : Some ( " SomeClass.someField " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
2020-04-09 08:34:24 -04:00
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " doc " ] ) ;
2020-04-09 08:34:24 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2020-07-12 08:16:33 -04:00
private : false ,
2020-04-09 08:34:24 -04:00
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-31 18:19:42 -04:00
lint : false ,
2023-10-30 18:58:57 -04:00
source_files : Default ::default ( ) ,
2020-04-09 08:34:24 -04:00
filter : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-04-09 08:34:24 -04:00
.. Flags ::default ( )
}
) ;
2023-10-30 18:58:57 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" --filter " ,
" Deno.Listener " ,
" --builtin "
] ) ;
2020-04-09 08:34:24 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2020-07-12 08:16:33 -04:00
private : false ,
2023-10-31 18:19:42 -04:00
lint : false ,
2020-04-09 08:34:24 -04:00
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-30 18:58:57 -04:00
source_files : DocSourceFileFlag ::Builtin ,
2020-04-09 08:34:24 -04:00
filter : Some ( " Deno.Listener " . to_string ( ) ) ,
2021-09-03 19:33:35 -04:00
} ) ,
2020-04-09 08:34:24 -04:00
.. Flags ::default ( )
}
) ;
2020-07-12 08:16:33 -04:00
2023-03-13 17:04:00 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" --no-npm " ,
" --no-remote " ,
" --private " ,
" path/to/module.js "
] ) ;
2020-07-12 08:16:33 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Doc ( DocFlags {
2020-07-12 08:16:33 -04:00
private : true ,
2023-10-31 18:19:42 -04:00
lint : false ,
2020-07-12 08:16:33 -04:00
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
source_files : DocSourceFileFlag ::Paths ( svec! [ " path/to/module.js " ] ) ,
2020-07-12 08:16:33 -04:00
filter : None ,
2021-09-03 19:33:35 -04:00
} ) ,
2023-03-13 17:04:00 -04:00
no_npm : true ,
no_remote : true ,
2020-07-12 08:16:33 -04:00
.. Flags ::default ( )
}
) ;
2023-10-30 18:58:57 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" path/to/module.js " ,
" path/to/module2.js "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Doc ( DocFlags {
private : false ,
2023-10-31 18:19:42 -04:00
lint : false ,
2023-10-30 18:58:57 -04:00
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-30 18:58:57 -04:00
source_files : DocSourceFileFlag ::Paths ( vec! [
" path/to/module.js " . to_string ( ) ,
" path/to/module2.js " . to_string ( )
] ) ,
filter : None ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" path/to/module.js " ,
" --builtin " ,
" path/to/module2.js "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Doc ( DocFlags {
private : false ,
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-31 18:19:42 -04:00
lint : false ,
source_files : DocSourceFileFlag ::Paths ( vec! [
" path/to/module.js " . to_string ( ) ,
" path/to/module2.js " . to_string ( )
] ) ,
filter : None ,
} ) ,
.. Flags ::default ( )
}
) ;
2023-11-03 13:06:18 -04:00
let r = flags_from_vec ( svec! [ " deno " , " doc " , " --lint " , ] ) ;
assert! ( r . is_err ( ) ) ;
2023-10-31 18:19:42 -04:00
let r = flags_from_vec ( svec! [
" deno " ,
" doc " ,
" --lint " ,
" path/to/module.js " ,
" path/to/module2.js "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Doc ( DocFlags {
private : false ,
lint : true ,
json : false ,
2023-11-01 11:25:05 -04:00
html : None ,
2023-10-30 18:58:57 -04:00
source_files : DocSourceFileFlag ::Paths ( vec! [
" path/to/module.js " . to_string ( ) ,
" path/to/module2.js " . to_string ( )
] ) ,
filter : None ,
} ) ,
.. Flags ::default ( )
}
) ;
2020-04-02 09:26:40 -04:00
}
2020-03-27 16:09:51 -04:00
2020-04-02 09:26:40 -04:00
#[ test ]
fn inspect_default_host ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [ " deno " , " run " , " --inspect " , " foo.js " ] ) ;
2020-04-02 09:26:40 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" foo.js " . to_string ( ) ,
) ) ,
2020-04-03 13:40:11 -04:00
inspect : Some ( " 127.0.0.1:9229 " . parse ( ) . unwrap ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2020-04-02 09:26:40 -04:00
.. Flags ::default ( )
}
) ;
}
2020-11-30 14:35:12 -05:00
2022-12-12 09:33:30 -05:00
#[ test ]
fn inspect_wait ( ) {
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --inspect-wait " , " foo.js " ] ) ;
2022-12-12 09:33:30 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " foo.js " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2022-12-12 09:33:30 -05:00
inspect_wait : Some ( " 127.0.0.1:9229 " . parse ( ) . unwrap ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-12-12 09:33:30 -05:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --inspect-wait=127.0.0.1:3567 " ,
" foo.js "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" foo.js " . to_string ( ) ,
) ) ,
2022-12-12 09:33:30 -05:00
inspect_wait : Some ( " 127.0.0.1:3567 " . parse ( ) . unwrap ( ) ) ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-12-12 09:33:30 -05:00
.. Flags ::default ( )
}
) ;
}
2020-11-30 14:35:12 -05:00
#[ test ]
fn compile ( ) {
2021-01-07 13:06:08 -05:00
let r = flags_from_vec ( svec! [
2020-11-30 14:35:12 -05:00
" deno " ,
" compile " ,
2023-12-01 21:20:06 -05:00
" https://examples.deno.land/color-logging.ts "
2020-11-30 14:35:12 -05:00
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Compile ( CompileFlags {
2023-12-01 21:20:06 -05:00
source_file : " https://examples.deno.land/color-logging.ts "
. to_string ( ) ,
2021-01-04 18:15:52 -05:00
output : None ,
args : vec ! [ ] ,
2021-01-18 21:40:22 -05:00
target : None ,
2023-07-28 11:46:26 -04:00
no_terminal : false ,
2024-08-15 00:42:23 -04:00
icon : None ,
2023-03-18 19:43:07 -04:00
include : vec ! [ ]
2021-09-03 19:33:35 -04:00
} ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2020-11-30 14:35:12 -05:00
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn compile_with_flags ( ) {
#[ rustfmt::skip ]
2024-08-27 23:23:51 -04:00
let r = flags_from_vec ( svec! [ " deno " , " compile " , " --import-map " , " import_map.json " , " --no-remote " , " --config " , " tsconfig.json " , " --no-check " , " --unsafely-ignore-certificate-errors " , " --reload " , " --lock " , " lock.json " , " --cert " , " example.crt " , " --cached-only " , " --location " , " https:foo " , " --allow-read " , " --allow-net " , " --v8-flags=--help " , " --seed " , " 1 " , " --no-terminal " , " --icon " , " favicon.ico " , " --output " , " colors " , " --env=.example.env " , " https://examples.deno.land/color-logging.ts " , " foo " , " bar " , " -p " , " 8080 " ] ) ;
2020-11-30 14:35:12 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Compile ( CompileFlags {
2023-12-01 21:20:06 -05:00
source_file : " https://examples.deno.land/color-logging.ts "
. to_string ( ) ,
2024-03-14 19:53:46 -04:00
output : Some ( String ::from ( " colors " ) ) ,
2023-09-08 13:14:59 -04:00
args : svec ! [ " foo " , " bar " , " -p " , " 8080 " ] ,
2021-01-18 21:40:22 -05:00
target : None ,
2023-07-28 11:46:26 -04:00
no_terminal : true ,
2024-08-15 00:42:23 -04:00
icon : Some ( String ::from ( " favicon.ico " ) ) ,
2023-03-18 19:43:07 -04:00
include : vec ! [ ]
2021-09-03 19:33:35 -04:00
} ) ,
2020-11-30 14:35:12 -05:00
import_map_path : Some ( " import_map.json " . to_string ( ) ) ,
no_remote : true ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " tsconfig.json " . to_owned ( ) ) ,
2022-04-10 19:12:51 -04:00
type_check_mode : TypeCheckMode ::None ,
2020-11-30 14:35:12 -05:00
reload : true ,
2024-03-14 19:53:46 -04:00
lock : Some ( String ::from ( " lock.json " ) ) ,
2023-01-17 19:18:24 -05:00
ca_data : Some ( CaData ::File ( " example.crt " . to_string ( ) ) ) ,
2021-01-04 18:15:52 -05:00
cached_only : true ,
2021-01-07 13:06:08 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_read : Some ( vec! [ ] ) ,
allow_net : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
2021-08-10 07:19:45 -04:00
unsafely_ignore_certificate_errors : Some ( vec! [ ] ) ,
2021-01-04 18:15:52 -05:00
v8_flags : svec ! [ " --help " , " --random-seed=1 " ] ,
seed : Some ( 1 ) ,
2023-11-01 11:21:13 -04:00
env_file : Some ( " .example.env " . to_owned ( ) ) ,
2020-11-30 14:35:12 -05:00
.. Flags ::default ( )
}
) ;
}
2021-01-23 20:18:19 -05:00
2021-02-24 09:27:51 -05:00
#[ test ]
fn coverage ( ) {
let r = flags_from_vec ( svec! [ " deno " , " coverage " , " foo.json " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2021-09-03 19:33:35 -04:00
subcommand : DenoSubcommand ::Coverage ( CoverageFlags {
2023-01-13 16:56:29 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " foo.json " . to_string ( ) ] ,
2023-01-13 16:56:29 -05:00
ignore : vec ! [ ] ,
} ,
2021-02-24 09:27:51 -05:00
include : vec ! [ r "^file:" . to_string ( ) ] ,
exclude : vec ! [ r "test\.(js|mjs|ts|jsx|tsx)$" . to_string ( ) ] ,
2023-12-18 05:48:45 -05:00
.. CoverageFlags ::default ( )
2021-09-03 19:33:35 -04:00
} ) ,
2021-02-24 09:27:51 -05:00
.. Flags ::default ( )
}
) ;
}
2022-02-15 10:33:21 -05:00
#[ test ]
fn coverage_with_lcov_and_out_file ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" coverage " ,
" --lcov " ,
" --output=foo.lcov " ,
" foo.json "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Coverage ( CoverageFlags {
2023-01-13 16:56:29 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " foo.json " . to_string ( ) ] ,
2023-01-13 16:56:29 -05:00
ignore : vec ! [ ] ,
} ,
2022-02-15 10:33:21 -05:00
include : vec ! [ r "^file:" . to_string ( ) ] ,
exclude : vec ! [ r "test\.(js|mjs|ts|jsx|tsx)$" . to_string ( ) ] ,
2023-12-08 02:54:52 -05:00
r#type : CoverageType ::Lcov ,
2024-03-14 19:53:46 -04:00
output : Some ( String ::from ( " foo.lcov " ) ) ,
2022-02-15 10:33:21 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
}
2023-12-18 05:48:45 -05:00
#[ test ]
fn coverage_with_default_files ( ) {
let r = flags_from_vec ( svec! [ " deno " , " coverage " , ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Coverage ( CoverageFlags {
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " coverage " . to_string ( ) ] ,
2023-12-18 05:48:45 -05:00
ignore : vec ! [ ] ,
} ,
include : vec ! [ r "^file:" . to_string ( ) ] ,
exclude : vec ! [ r "test\.(js|mjs|ts|jsx|tsx)$" . to_string ( ) ] ,
.. CoverageFlags ::default ( )
} ) ,
.. Flags ::default ( )
}
) ;
}
2021-01-23 20:18:19 -05:00
#[ test ]
fn location_with_bad_scheme ( ) {
#[ rustfmt::skip ]
let r = flags_from_vec ( svec! [ " deno " , " run " , " --location " , " foo: " , " mod.ts " ] ) ;
assert! ( r . is_err ( ) ) ;
assert! ( r
. unwrap_err ( )
. to_string ( )
. contains ( " Expected protocol \" http \" or \" https \" " ) ) ;
}
2021-10-04 19:35:55 -04:00
2022-01-17 20:10:17 -05:00
#[ test ]
fn test_config_path_args ( ) {
let flags = flags_from_vec ( svec! [ " deno " , " run " , " foo.js " ] ) . unwrap ( ) ;
2023-03-13 21:12:09 -04:00
let cwd = std ::env ::current_dir ( ) . unwrap ( ) ;
2024-07-03 20:54:33 -04:00
assert_eq! ( flags . config_path_args ( & cwd ) , Some ( vec! [ cwd . clone ( ) ] ) ) ;
let flags = flags_from_vec ( svec! [ " deno " , " run " , " sub_dir/foo.js " ] ) . unwrap ( ) ;
let cwd = std ::env ::current_dir ( ) . unwrap ( ) ;
assert_eq! (
flags . config_path_args ( & cwd ) ,
Some ( vec! [ cwd . join ( " sub_dir " ) . clone ( ) ] )
) ;
2022-01-17 20:10:17 -05:00
2022-02-25 00:39:18 -05:00
let flags =
2024-08-08 10:22:28 -04:00
flags_from_vec ( svec! [ " deno " , " https://example.com/foo.js " ] ) . unwrap ( ) ;
2023-03-13 21:12:09 -04:00
assert_eq! ( flags . config_path_args ( & cwd ) , None ) ;
2022-02-25 00:39:18 -05:00
2022-01-17 20:10:17 -05:00
let flags =
2024-07-03 20:54:33 -04:00
flags_from_vec ( svec! [ " deno " , " lint " , " dir/a/a.js " , " dir/b/b.js " ] )
. unwrap ( ) ;
2022-01-17 20:10:17 -05:00
assert_eq! (
2023-03-13 21:12:09 -04:00
flags . config_path_args ( & cwd ) ,
2024-07-08 10:12:10 -04:00
Some ( vec! [ cwd . join ( " dir/a/a.js " ) , cwd . join ( " dir/b/b.js " ) ] )
2022-01-17 20:10:17 -05:00
) ;
let flags = flags_from_vec ( svec! [ " deno " , " lint " ] ) . unwrap ( ) ;
2024-07-03 20:54:33 -04:00
assert_eq! ( flags . config_path_args ( & cwd ) , Some ( vec! [ cwd . clone ( ) ] ) ) ;
2022-01-17 20:10:17 -05:00
2024-07-03 20:54:33 -04:00
let flags = flags_from_vec ( svec! [
" deno " ,
" fmt " ,
" dir/a/a.js " ,
" dir/a/a2.js " ,
" dir/b.js "
] )
. unwrap ( ) ;
2022-01-17 20:10:17 -05:00
assert_eq! (
2023-03-13 21:12:09 -04:00
flags . config_path_args ( & cwd ) ,
2024-07-08 10:12:10 -04:00
Some ( vec! [
cwd . join ( " dir/a/a.js " ) ,
cwd . join ( " dir/a/a2.js " ) ,
cwd . join ( " dir/b.js " )
] )
2022-01-17 20:10:17 -05:00
) ;
}
2022-01-31 11:39:39 -05:00
#[ test ]
fn test_no_clear_watch_flag_without_watch_flag ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --no-clear-screen " , " foo.js " ] ) ;
assert! ( r . is_err ( ) ) ;
let error_message = r . unwrap_err ( ) . to_string ( ) ;
assert! ( & error_message
2023-03-26 00:06:18 -04:00
. contains ( " error: the following required arguments were not provided: " ) ) ;
2022-03-27 21:57:56 -04:00
assert! ( & error_message . contains ( " --watch[=<FILES>...] " ) ) ;
2022-01-31 11:39:39 -05:00
}
2022-02-16 13:14:19 -05:00
2022-03-10 20:56:14 -05:00
#[ test ]
fn task_subcommand ( ) {
2022-04-27 15:43:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " task " , " build " , " hello " , " world " , ] ) ;
2022-03-10 20:56:14 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-03-10 20:56:14 -05:00
} ) ,
argv : svec ! [ " hello " , " world " ] ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " task " , " build " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-06-08 17:30:16 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " task " , " --cwd " , " foo " , " build " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
cwd : Some ( " foo " . to_string ( ) ) ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-03-10 20:56:14 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
}
2022-04-27 15:43:36 -04:00
#[ test ]
fn task_subcommand_double_hyphen ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" task " ,
" -c " ,
" deno.json " ,
" build " ,
" -- " ,
" hello " ,
" world " ,
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-04-27 15:43:36 -04:00
} ) ,
argv : svec ! [ " -- " , " hello " , " world " ] ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " deno.json " . to_owned ( ) ) ,
2022-04-27 15:43:36 -04:00
.. Flags ::default ( )
2022-04-29 19:51:10 -04:00
}
) ;
2022-06-08 17:30:16 -04:00
let r = flags_from_vec ( svec! [
" deno " , " task " , " --cwd " , " foo " , " build " , " -- " , " hello " , " world "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
cwd : Some ( " foo " . to_string ( ) ) ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-06-08 17:30:16 -04:00
} ) ,
argv : svec ! [ " -- " , " hello " , " world " ] ,
.. Flags ::default ( )
}
) ;
2022-04-29 19:51:10 -04:00
}
#[ test ]
fn task_subcommand_double_hyphen_only ( ) {
// edge case, but it should forward
let r = flags_from_vec ( svec! [ " deno " , " task " , " build " , " -- " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-04-29 19:51:10 -04:00
} ) ,
argv : svec ! [ " -- " ] ,
.. Flags ::default ( )
2022-04-27 15:43:36 -04:00
}
) ;
}
2022-04-29 10:29:14 -04:00
#[ test ]
fn task_following_arg ( ) {
let r = flags_from_vec ( svec! [ " deno " , " task " , " build " , " -1 " , " --test " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-04-29 10:29:14 -04:00
} ) ,
argv : svec ! [ " -1 " , " --test " ] ,
.. Flags ::default ( )
}
) ;
}
2022-05-11 12:58:35 -04:00
#[ test ]
fn task_following_double_hyphen_arg ( ) {
let r = flags_from_vec ( svec! [ " deno " , " task " , " build " , " --test " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-05-11 12:58:35 -04:00
} ) ,
argv : svec ! [ " --test " ] ,
.. Flags ::default ( )
}
) ;
}
2022-08-10 11:55:34 -04:00
#[ test ]
fn task_with_global_flags ( ) {
// can fail if the custom parser in task_parse() starts at the wrong index
2024-08-18 18:39:53 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --quiet " , " task " , " build " ] ) ;
2022-08-10 11:55:34 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
cwd : None ,
2023-02-22 22:45:35 -05:00
task : Some ( " build " . to_string ( ) ) ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-08-10 11:55:34 -04:00
} ) ,
log_level : Some ( log ::Level ::Error ) ,
.. Flags ::default ( )
}
) ;
}
2022-03-10 20:56:14 -05:00
#[ test ]
fn task_subcommand_empty ( ) {
2022-04-27 15:43:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " task " ] ) ;
2022-03-10 20:56:14 -05:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : None ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-03-10 20:56:14 -05:00
} ) ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn task_subcommand_config ( ) {
let r = flags_from_vec ( svec! [ " deno " , " task " , " --config " , " deno.jsonc " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : None ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-03-10 20:56:14 -05:00
} ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " deno.jsonc " . to_string ( ) ) ,
2022-03-10 20:56:14 -05:00
.. Flags ::default ( )
}
2022-05-11 12:58:35 -04:00
) ;
}
#[ test ]
fn task_subcommand_config_short ( ) {
let r = flags_from_vec ( svec! [ " deno " , " task " , " -c " , " deno.jsonc " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Task ( TaskFlags {
2022-06-08 17:30:16 -04:00
cwd : None ,
2023-02-22 22:45:35 -05:00
task : None ,
2024-08-21 09:54:59 -04:00
is_run : false ,
2022-05-11 12:58:35 -04:00
} ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Path ( " deno.jsonc " . to_string ( ) ) ,
2022-05-11 12:58:35 -04:00
.. Flags ::default ( )
}
2022-03-10 20:56:14 -05:00
) ;
}
2022-03-11 17:07:02 -05:00
2022-06-28 15:47:51 -04:00
#[ test ]
fn task_subcommand_noconfig_invalid ( ) {
let r = flags_from_vec ( svec! [ " deno " , " task " , " --no-config " ] ) ;
2023-03-26 00:06:18 -04:00
assert_eq! (
r . unwrap_err ( ) . kind ( ) ,
clap ::error ::ErrorKind ::UnknownArgument
) ;
2022-06-28 15:47:51 -04:00
}
2022-03-11 17:07:02 -05:00
#[ test ]
fn bench_with_flags ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" bench " ,
2023-02-12 12:40:45 -05:00
" --json " ,
2022-03-11 17:07:02 -05:00
" --unstable " ,
2023-03-13 17:04:00 -04:00
" --no-npm " ,
" --no-remote " ,
2023-03-26 10:55:58 -04:00
" --no-run " ,
2022-03-11 17:07:02 -05:00
" --filter " ,
" - foo " ,
" --location " ,
" https:foo " ,
" --allow-net " ,
" dir1/ " ,
" dir2/ " ,
" -- " ,
" arg1 " ,
" arg2 "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Bench ( BenchFlags {
filter : Some ( " - foo " . to_string ( ) ) ,
2023-02-12 12:40:45 -05:00
json : true ,
2023-03-26 10:55:58 -04:00
no_run : true ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
2024-01-15 19:15:39 -05:00
include : vec ! [ " dir1/ " . to_string ( ) , " dir2/ " . to_string ( ) ] ,
2023-01-07 15:22:09 -05:00
ignore : vec ! [ ] ,
} ,
2023-06-15 13:09:37 -04:00
watch : Default ::default ( ) ,
2022-03-11 17:07:02 -05:00
} ) ,
2024-01-22 12:37:28 -05:00
unstable_config : UnstableConfig {
legacy_flag_enabled : true ,
.. Default ::default ( )
} ,
2023-03-13 17:04:00 -04:00
no_npm : true ,
no_remote : true ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2022-03-11 17:07:02 -05:00
location : Some ( Url ::parse ( " https://foo/ " ) . unwrap ( ) ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
allow_net : Some ( vec! [ ] ) ,
no_prompt : true ,
.. Default ::default ( )
} ,
2022-03-11 17:07:02 -05:00
argv : svec ! [ " arg1 " , " arg2 " ] ,
.. Flags ::default ( )
}
) ;
}
2022-04-10 19:12:51 -04:00
2023-01-07 15:22:09 -05:00
#[ test ]
fn bench_watch ( ) {
let r = flags_from_vec ( svec! [ " deno " , " bench " , " --watch " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Bench ( BenchFlags {
filter : None ,
2023-02-12 12:40:45 -05:00
json : false ,
2023-03-26 10:55:58 -04:00
no_run : false ,
2023-01-07 15:22:09 -05:00
files : FileFlags {
include : vec ! [ ] ,
ignore : vec ! [ ] ,
} ,
2023-10-30 20:25:58 -04:00
watch : Some ( Default ::default ( ) ) ,
2023-01-07 15:22:09 -05:00
} ) ,
2024-05-06 19:21:58 -04:00
permissions : PermissionFlags {
no_prompt : true ,
.. Default ::default ( )
} ,
2023-01-07 15:22:09 -05:00
type_check_mode : TypeCheckMode ::Local ,
.. Flags ::default ( )
}
) ;
}
2022-04-10 19:12:51 -04:00
#[ test ]
fn run_with_check ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --check " , " script.ts " , ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::Local ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-04-10 19:12:51 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " run " , " --check=all " , " script.ts " , ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::All ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-04-10 19:12:51 -04:00
.. Flags ::default ( )
}
) ;
2024-08-08 10:22:28 -04:00
let r = flags_from_vec ( svec! [ " deno " , " --check=foo " , " script.ts " , ] ) ;
2022-04-10 19:12:51 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2022-06-13 17:13:16 -04:00
type_check_mode : TypeCheckMode ::None ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-04-10 19:12:51 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --no-check " ,
" --check " ,
" script.ts " ,
] ) ;
assert! ( r . is_err ( ) ) ;
}
2022-05-13 11:40:50 -04:00
#[ test ]
fn no_config ( ) {
let r = flags_from_vec ( svec! [ " deno " , " run " , " --no-config " , " script.ts " , ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2023-12-06 16:36:06 -05:00
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
2022-05-13 11:40:50 -04:00
config_flag : ConfigFlag ::Disabled ,
2024-04-17 10:19:55 -04:00
code_cache_enabled : true ,
2022-05-13 11:40:50 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" run " ,
" --config " ,
" deno.json " ,
" --no-config " ,
" script.ts " ,
] ) ;
assert! ( r . is_err ( ) ) ;
}
2022-08-19 19:37:05 -04:00
#[ test ]
fn init ( ) {
let r = flags_from_vec ( svec! [ " deno " , " init " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-07-09 21:13:34 -04:00
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : None ,
2024-08-08 12:54:39 -04:00
lib : false ,
serve : false ,
2024-07-09 21:13:34 -04:00
} ) ,
2022-08-19 19:37:05 -04:00
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " init " , " foo " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : Some ( String ::from ( " foo " ) ) ,
2024-08-08 12:54:39 -04:00
lib : false ,
serve : false ,
2022-08-19 19:37:05 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
2022-09-02 11:59:36 -04:00
let r = flags_from_vec ( svec! [ " deno " , " init " , " --quiet " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-07-09 21:13:34 -04:00
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : None ,
2024-08-08 12:54:39 -04:00
lib : false ,
serve : false ,
2024-07-09 21:13:34 -04:00
} ) ,
2022-09-02 11:59:36 -04:00
log_level : Some ( Level ::Error ) ,
.. Flags ::default ( )
}
) ;
2024-07-09 21:13:34 -04:00
let r = flags_from_vec ( svec! [ " deno " , " init " , " --lib " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : None ,
2024-08-08 12:54:39 -04:00
lib : true ,
serve : false ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " init " , " --serve " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : None ,
lib : false ,
serve : true ,
2024-07-09 21:13:34 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " init " , " foo " , " --lib " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Init ( InitFlags {
dir : Some ( String ::from ( " foo " ) ) ,
2024-08-08 12:54:39 -04:00
lib : true ,
serve : false ,
2024-07-09 21:13:34 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
2022-08-19 19:37:05 -04:00
}
2023-09-15 20:42:09 -04:00
#[ test ]
fn jupyter ( ) {
2024-01-22 12:37:28 -05:00
let r = flags_from_vec ( svec! [ " deno " , " jupyter " ] ) ;
2023-09-15 20:42:09 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Jupyter ( JupyterFlags {
install : false ,
kernel : false ,
conn_file : None ,
} ) ,
.. Flags ::default ( )
}
) ;
2024-01-22 12:37:28 -05:00
let r = flags_from_vec ( svec! [ " deno " , " jupyter " , " --install " ] ) ;
2023-09-15 20:42:09 -04:00
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Jupyter ( JupyterFlags {
install : true ,
kernel : false ,
conn_file : None ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" jupyter " ,
" --kernel " ,
" --conn " ,
" path/to/conn/file "
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Jupyter ( JupyterFlags {
install : false ,
kernel : true ,
2024-03-14 19:53:46 -04:00
conn_file : Some ( String ::from ( " path/to/conn/file " ) ) ,
2023-09-15 20:42:09 -04:00
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [
" deno " ,
" jupyter " ,
" --install " ,
" --conn " ,
" path/to/conn/file "
] ) ;
r . unwrap_err ( ) ;
let r = flags_from_vec ( svec! [ " deno " , " jupyter " , " --kernel " , ] ) ;
r . unwrap_err ( ) ;
let r = flags_from_vec ( svec! [ " deno " , " jupyter " , " --install " , " --kernel " , ] ) ;
r . unwrap_err ( ) ;
}
2024-02-21 08:35:25 -05:00
#[ test ]
fn publish_args ( ) {
let r = flags_from_vec ( svec! [
" deno " ,
" publish " ,
2024-02-29 11:18:47 -05:00
" --no-provenance " ,
2024-02-21 08:35:25 -05:00
" --dry-run " ,
" --allow-slow-types " ,
2024-03-07 16:13:36 -05:00
" --allow-dirty " ,
2024-02-21 08:35:25 -05:00
" --token=asdf " ,
] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Publish ( PublishFlags {
token : Some ( " asdf " . to_string ( ) ) ,
dry_run : true ,
allow_slow_types : true ,
2024-03-07 16:13:36 -05:00
allow_dirty : true ,
2024-02-29 11:18:47 -05:00
no_provenance : true ,
2024-02-21 08:35:25 -05:00
} ) ,
type_check_mode : TypeCheckMode ::Local ,
.. Flags ::default ( )
}
) ;
}
2024-02-29 14:12:04 -05:00
#[ test ]
fn add_subcommand ( ) {
let r = flags_from_vec ( svec! [ " deno " , " add " ] ) ;
r . unwrap_err ( ) ;
let r = flags_from_vec ( svec! [ " deno " , " add " , " @david/which " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Add ( AddFlags {
packages : svec ! [ " @david/which " ] ,
} ) ,
.. Flags ::default ( )
}
) ;
let r = flags_from_vec ( svec! [ " deno " , " add " , " @david/which " , " @luca/hello " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Add ( AddFlags {
packages : svec ! [ " @david/which " , " @luca/hello " ] ,
} ) ,
.. Flags ::default ( )
}
) ;
}
2024-07-02 18:00:16 -04:00
2024-08-12 16:17:25 -04:00
#[ test ]
fn remove_subcommand ( ) {
let r = flags_from_vec ( svec! [ " deno " , " remove " ] ) ;
r . unwrap_err ( ) ;
let r = flags_from_vec ( svec! [ " deno " , " remove " , " @david/which " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Remove ( RemoveFlags {
packages : svec ! [ " @david/which " ] ,
} ) ,
.. Flags ::default ( )
}
) ;
let r =
flags_from_vec ( svec! [ " deno " , " remove " , " @david/which " , " @luca/hello " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Remove ( RemoveFlags {
packages : svec ! [ " @david/which " , " @luca/hello " ] ,
} ) ,
.. Flags ::default ( )
}
) ;
}
2024-07-02 18:00:16 -04:00
#[ test ]
fn run_with_frozen_lockfile ( ) {
let cases = [
2024-08-20 10:55:47 -04:00
( Some ( " --frozen " ) , Some ( true ) ) ,
( Some ( " --frozen=true " ) , Some ( true ) ) ,
( Some ( " --frozen=false " ) , Some ( false ) ) ,
( None , None ) ,
2024-07-02 18:00:16 -04:00
] ;
for ( flag , frozen ) in cases {
let mut args = svec! [ " deno " , " run " ] ;
if let Some ( f ) = flag {
args . push ( f . into ( ) ) ;
}
args . push ( " script.ts " . into ( ) ) ;
let r = flags_from_vec ( args ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Run ( RunFlags ::new_default (
" script.ts " . to_string ( ) ,
) ) ,
frozen_lockfile : frozen ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
}
2024-07-09 23:06:08 -04:00
#[ test ]
fn allow_scripts ( ) {
let cases = [
( Some ( " --allow-scripts " ) , Ok ( PackagesAllowedScripts ::All ) ) ,
( None , Ok ( PackagesAllowedScripts ::None ) ) ,
(
Some ( " --allow-scripts=npm:foo " ) ,
Ok ( PackagesAllowedScripts ::Some ( svec! [ " npm:foo " ] ) ) ,
) ,
(
Some ( " --allow-scripts=npm:foo,npm:bar " ) ,
Ok ( PackagesAllowedScripts ::Some ( svec! [ " npm:foo " , " npm:bar " ] ) ) ,
) ,
( Some ( " --allow-scripts=foo " ) , Err ( " Invalid package " ) ) ,
] ;
for ( flag , value ) in cases {
let mut args = svec! [ " deno " , " cache " ] ;
if let Some ( flag ) = flag {
args . push ( flag . into ( ) ) ;
}
args . push ( " script.ts " . into ( ) ) ;
let r = flags_from_vec ( args ) ;
match value {
Ok ( value ) = > {
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Cache ( CacheFlags {
files : svec ! [ " script.ts " ] ,
} ) ,
allow_scripts : value ,
.. Flags ::default ( )
}
) ;
}
Err ( e ) = > {
let err = r . unwrap_err ( ) ;
assert! (
err . to_string ( ) . contains ( e ) ,
" expected to contain '{e}' got '{err}' "
) ;
}
}
}
}
2024-08-08 10:22:28 -04:00
#[ test ]
fn bare_run ( ) {
let r = flags_from_vec ( svec! [ " deno " , " --no-config " , " script.ts " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
2024-08-12 11:55:33 -04:00
subcommand : DenoSubcommand ::Run ( RunFlags {
script : " script.ts " . to_string ( ) ,
watch : None ,
bare : true ,
} ) ,
2024-08-08 10:22:28 -04:00
config_flag : ConfigFlag ::Disabled ,
code_cache_enabled : true ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn bare_global ( ) {
let r = flags_from_vec ( svec! [ " deno " , " --log-level=debug " ] ) ;
assert_eq! (
r . unwrap ( ) ,
Flags {
subcommand : DenoSubcommand ::Repl ( ReplFlags {
eval_files : None ,
eval : None ,
is_default_command : true ,
} ) ,
log_level : Some ( Level ::Debug ) ,
permissions : PermissionFlags {
allow_all : false ,
allow_net : Some ( vec! [ ] ) ,
allow_env : Some ( vec! [ ] ) ,
allow_run : Some ( vec! [ ] ) ,
allow_read : Some ( vec! [ ] ) ,
allow_sys : Some ( vec! [ ] ) ,
allow_write : Some ( vec! [ ] ) ,
allow_ffi : Some ( vec! [ ] ) ,
.. Default ::default ( )
} ,
.. Flags ::default ( )
}
) ;
}
#[ test ]
fn bare_with_flag_no_file ( ) {
let r = flags_from_vec ( svec! [ " deno " , " --no-config " ] ) ;
let err = r . unwrap_err ( ) ;
assert! ( err . to_string ( ) . contains ( " error: [SCRIPT_ARG] may only be omitted with --v8-flags=--help, else to use the repl with arguments, please use the `deno repl` subcommand " ) ) ;
assert! ( err
. to_string ( )
. contains ( " Usage: deno [OPTIONS] [COMMAND] [SCRIPT_ARG]... " ) ) ;
}
2024-08-21 09:54:59 -04:00
#[ test ]
fn equal_help_output ( ) {
for command in clap_root ( ) . get_subcommands ( ) {
if command . get_name ( ) = = " help " {
continue ;
}
let long_flag = if let DenoSubcommand ::Help ( help ) =
flags_from_vec ( svec! [ " deno " , command . get_name ( ) , " --help " ] )
. unwrap ( )
. subcommand
{
help . help . to_string ( )
} else {
unreachable! ( )
} ;
let short_flag = if let DenoSubcommand ::Help ( help ) =
flags_from_vec ( svec! [ " deno " , command . get_name ( ) , " -h " ] )
. unwrap ( )
. subcommand
{
help . help . to_string ( )
} else {
unreachable! ( )
} ;
let subcommand = if let DenoSubcommand ::Help ( help ) =
flags_from_vec ( svec! [ " deno " , " help " , command . get_name ( ) ] )
. unwrap ( )
. subcommand
{
help . help . to_string ( )
} else {
unreachable! ( )
} ;
assert_eq! ( long_flag , short_flag , " {} subcommand " , command . get_name ( ) ) ;
assert_eq! ( long_flag , subcommand , " {} subcommand " , command . get_name ( ) ) ;
}
}
2020-03-27 16:09:51 -04:00
}