1- use std:: process:: { Command , Stdio } ;
2-
3- use crate :: { Adapter , AdapterCompileError , shell:: SHELL } ;
1+ use crate :: { Adapter , AdapterCompileError } ;
42use async_trait:: async_trait;
53use camino:: Utf8PathBuf ;
64use serde:: Deserialize ;
7- use snafu:: { ResultExt , Snafu } ;
5+ use snafu:: { OptionExt , ResultExt , Snafu } ;
6+ use std:: process:: { Command , Stdio } ;
87
98/// Configuration for a custom canister build adapter.
109#[ derive( Debug , Deserialize ) ]
@@ -16,11 +15,22 @@ pub struct ScriptAdapter {
1615#[ async_trait]
1716impl Adapter for ScriptAdapter {
1817 async fn compile ( & self , path : Utf8PathBuf ) -> Result < ( ) , AdapterCompileError > {
18+ // Parse command input
19+ let input = shellwords:: split ( & self . command ) . context ( CommandParseSnafu {
20+ command : & self . command ,
21+ } ) ?;
22+
23+ // Separate command and args
24+ let ( cmd, args) = input. split_first ( ) . context ( InvalidCommandSnafu {
25+ command : & self . command ,
26+ reason : "command must include at least one element" . to_string ( ) ,
27+ } ) ?;
28+
1929 // Command
20- let mut cmd = Command :: new ( SHELL . binary ( ) ) ;
30+ let mut cmd = Command :: new ( cmd ) ;
2131
22- // Script
23- cmd. arg ( SHELL . exec_flag ( ) ) . arg ( & self . command ) ;
32+ // Args
33+ cmd. args ( args ) ;
2434
2535 // Set directory
2636 cmd. current_dir ( & path) ;
@@ -53,6 +63,15 @@ impl Adapter for ScriptAdapter {
5363
5464#[ derive( Debug , Snafu ) ]
5565pub enum ScriptAdapterCompileError {
66+ #[ snafu( display( "failed to parse command {command}: {source}" ) ) ]
67+ CommandParse {
68+ command : String ,
69+ source : shellwords:: MismatchedQuotes ,
70+ } ,
71+
72+ #[ snafu( display( "invalid command {command}: {reason}" ) ) ]
73+ InvalidCommand { command : String , reason : String } ,
74+
5675 #[ snafu( display( "failed to execute command {command}: {source}" ) ) ]
5776 CommandInvoke {
5877 command : String ,
0 commit comments