@@ -417,6 +417,42 @@ impl RunFlags {
417417 }
418418}
419419
420+ #[ derive( Clone , Debug , Eq , PartialEq , Default ) ]
421+ pub enum DenoXShimName {
422+ #[ default]
423+ Dx ,
424+ Denox ,
425+ Other ( String ) ,
426+ }
427+
428+ impl DenoXShimName {
429+ pub fn name ( & self ) -> & str {
430+ match self {
431+ Self :: Dx => "dx" ,
432+ Self :: Denox => "denox" ,
433+ Self :: Other ( name) => name,
434+ }
435+ }
436+ }
437+
438+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
439+ pub enum XFlagsKind {
440+ InstallAlias ( DenoXShimName ) ,
441+ Command ( XCommandFlags ) ,
442+ Print ,
443+ }
444+
445+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
446+ pub struct XCommandFlags {
447+ pub yes : bool ,
448+ pub command : String ,
449+ }
450+
451+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
452+ pub struct XFlags {
453+ pub kind : XFlagsKind ,
454+ }
455+
420456#[ derive( Clone , Debug , Eq , PartialEq ) ]
421457pub struct ServeFlags {
422458 pub script : String ,
@@ -585,6 +621,7 @@ pub enum DenoSubcommand {
585621 Vendor ,
586622 Publish ( PublishFlags ) ,
587623 Help ( HelpFlags ) ,
624+ X ( XFlags ) ,
588625}
589626
590627impl DenoSubcommand {
@@ -1584,6 +1621,20 @@ pub fn flags_from_vec_with_initial_cwd(
15841621 args : Vec < OsString > ,
15851622 initial_cwd : Option < PathBuf > ,
15861623) -> clap:: error:: Result < Flags > {
1624+ let args = if !args. is_empty ( )
1625+ && ( args[ 0 ] . as_encoded_bytes ( ) . ends_with ( b"dx" )
1626+ || args[ 0 ] . as_encoded_bytes ( ) . ends_with ( b"denox" ) )
1627+ {
1628+ let mut new_args = Vec :: with_capacity ( args. len ( ) + 1 ) ;
1629+ new_args. push ( args[ 0 ] . clone ( ) ) ;
1630+ new_args. push ( OsString :: from ( "x" ) ) ;
1631+ if args. len ( ) >= 2 {
1632+ new_args. extend ( args. into_iter ( ) . skip ( 1 ) ) ;
1633+ }
1634+ new_args
1635+ } else {
1636+ args
1637+ } ;
15871638 let mut app = clap_root ( ) ;
15881639 let mut matches =
15891640 app
@@ -1766,6 +1817,7 @@ pub fn flags_from_vec_with_initial_cwd(
17661817 "upgrade" => upgrade_parse ( & mut flags, & mut m) ,
17671818 "vendor" => vendor_parse ( & mut flags, & mut m) ,
17681819 "publish" => publish_parse ( & mut flags, & mut m) ?,
1820+ "x" => x_parse ( & mut flags, & mut m) ?,
17691821 _ => unreachable ! ( ) ,
17701822 }
17711823 }
@@ -2028,7 +2080,8 @@ pub fn clap_root() -> Command {
20282080 . subcommand ( types_subcommand ( ) )
20292081 . subcommand ( update_subcommand ( ) )
20302082 . subcommand ( upgrade_subcommand ( ) )
2031- . subcommand ( vendor_subcommand ( ) ) ;
2083+ . subcommand ( vendor_subcommand ( ) )
2084+ . subcommand ( x_subcommand ( ) ) ;
20322085
20332086 let help = help_subcommand ( & cmd) ;
20342087 cmd. subcommand ( help)
@@ -3548,6 +3601,46 @@ The installation root is determined, in order of precedence:
35483601 } )
35493602}
35503603
3604+ fn deno_x_shim_name_parser ( value : & str ) -> Result < DenoXShimName , String > {
3605+ match value {
3606+ "dx" => Ok ( DenoXShimName :: Dx ) ,
3607+ "denox" => Ok ( DenoXShimName :: Denox ) ,
3608+ _ => Ok ( DenoXShimName :: Other ( value. to_string ( ) ) ) ,
3609+ }
3610+ }
3611+
3612+ fn x_subcommand ( ) -> Command {
3613+ command (
3614+ "x" ,
3615+ cstr ! ( "Execute a binary from npm or jsr, like npx" ) ,
3616+ UnstableArgsConfig :: ResolutionAndRuntime ,
3617+ )
3618+ . defer ( |cmd| {
3619+ runtime_args ( cmd, true , true , true )
3620+ . arg ( script_arg ( ) . trailing_var_arg ( true ) )
3621+ . arg (
3622+ Arg :: new ( "yes" )
3623+ . long ( "yes" )
3624+ . short ( 'y' )
3625+ . help ( "Assume confirmation for all prompts" )
3626+ . action ( ArgAction :: SetTrue )
3627+ . conflicts_with ( "install-alias" ) ,
3628+ )
3629+ . arg ( check_arg ( false ) )
3630+ . arg ( env_file_arg ( ) )
3631+ . arg (
3632+ Arg :: new ( "install-alias" )
3633+ . long ( "install-alias" )
3634+ . num_args ( 0 ..=1 )
3635+ . default_missing_value ( "dx" )
3636+ . require_equals ( true )
3637+ . value_parser ( deno_x_shim_name_parser)
3638+ . action ( ArgAction :: Set )
3639+ . conflicts_with ( "script_arg" ) ,
3640+ )
3641+ } )
3642+ }
3643+
35513644fn lsp_subcommand ( ) -> Command {
35523645 Command :: new ( "lsp" ) . about (
35533646 "The 'deno lsp' subcommand provides a way for code editors and IDEs to interact with Deno
@@ -6760,6 +6853,35 @@ fn compile_args_without_check_parse(
67606853 Ok ( ( ) )
67616854}
67626855
6856+ fn x_parse (
6857+ flags : & mut Flags ,
6858+ matches : & mut ArgMatches ,
6859+ ) -> clap:: error:: Result < ( ) > {
6860+ let kind = if let Some ( shim_name) =
6861+ matches. remove_one :: < DenoXShimName > ( "install-alias" )
6862+ {
6863+ XFlagsKind :: InstallAlias ( shim_name)
6864+ } else if let Some ( mut script_arg) =
6865+ matches. remove_many :: < String > ( "script_arg" )
6866+ {
6867+ if let Some ( command) = script_arg. next ( ) {
6868+ let yes = matches. get_flag ( "yes" ) ;
6869+ flags. argv . extend ( script_arg) ;
6870+ runtime_args_parse ( flags, matches, true , true , true ) ?;
6871+ XFlagsKind :: Command ( XCommandFlags { yes, command } )
6872+ } else {
6873+ XFlagsKind :: Print
6874+ }
6875+ } else {
6876+ XFlagsKind :: Print
6877+ } ;
6878+ if !flags. permissions . has_permission ( ) && flags. permission_set . is_none ( ) {
6879+ flags. permissions . allow_all = true ;
6880+ }
6881+ flags. subcommand = DenoSubcommand :: X ( XFlags { kind } ) ;
6882+ Ok ( ( ) )
6883+ }
6884+
67636885fn escape_and_split_commas ( s : String ) -> Result < Vec < String > , clap:: Error > {
67646886 let mut result = vec ! [ ] ;
67656887 let mut current = String :: new ( ) ;
0 commit comments