1+ mod app_source;
2+
13use std:: {
24 collections:: HashSet ,
35 ffi:: OsString ,
4- fmt:: { Debug , Display } ,
6+ fmt:: Debug ,
57 path:: { Path , PathBuf } ,
68} ;
79
@@ -16,6 +18,8 @@ use tempfile::TempDir;
1618
1719use crate :: opts:: * ;
1820
21+ use self :: app_source:: AppSource ;
22+
1923const APPLICATION_OPT : & str = "APPLICATION" ;
2024
2125/// Start the Fermyon runtime.
@@ -243,8 +247,8 @@ impl UpCommand {
243247 fn resolve_app_source ( & self ) -> AppSource {
244248 match ( & self . app_source , & self . file_source , & self . registry_source ) {
245249 ( None , None , None ) => self . default_manifest_or_none ( ) ,
246- ( Some ( source) , None , None ) => Self :: infer_source ( source) ,
247- ( None , Some ( file) , None ) => Self :: infer_file_source ( file. to_owned ( ) ) ,
250+ ( Some ( source) , None , None ) => AppSource :: infer_source ( source) ,
251+ ( None , Some ( file) , None ) => AppSource :: infer_file_source ( file. to_owned ( ) ) ,
248252 ( None , None , Some ( reference) ) => AppSource :: OciRegistry ( reference. to_owned ( ) ) ,
249253 _ => AppSource :: unresolvable ( "More than one application source was specified" ) ,
250254 }
@@ -265,24 +269,6 @@ impl UpCommand {
265269 }
266270 }
267271
268- fn infer_source ( source : & str ) -> AppSource {
269- let path = PathBuf :: from ( source) ;
270- if path. exists ( ) {
271- Self :: infer_file_source ( path)
272- } else if spin_oci:: is_probably_oci_reference ( source) {
273- AppSource :: OciRegistry ( source. to_owned ( ) )
274- } else {
275- AppSource :: Unresolvable ( format ! ( "File or directory '{source}' not found. If you meant to load from a registry, use the `--from-registry` option." ) )
276- }
277- }
278-
279- fn infer_file_source ( path : impl Into < PathBuf > ) -> AppSource {
280- match spin_common:: paths:: resolve_manifest_file_path ( path. into ( ) ) {
281- Ok ( file) => AppSource :: File ( file) ,
282- Err ( e) => AppSource :: Unresolvable ( e. to_string ( ) ) ,
283- }
284- }
285-
286272 fn trigger_args_look_file_like ( & self ) -> bool {
287273 // Heuristic for the user typing `spin up foo` instead of `spin up -f foo` - in the
288274 // first case `foo` gets interpreted as a trigger arg which is probably not what the
@@ -430,50 +416,10 @@ fn trigger_command_from_locked_app(locked_app: &LockedApp) -> Result<Vec<String>
430416 }
431417}
432418
433- #[ derive( Debug , PartialEq , Eq ) ]
434- enum AppSource {
435- None ,
436- File ( PathBuf ) ,
437- OciRegistry ( String ) ,
438- Unresolvable ( String ) ,
439- }
440-
441- impl AppSource {
442- fn unresolvable ( message : impl Into < String > ) -> Self {
443- Self :: Unresolvable ( message. into ( ) )
444- }
445-
446- fn local_app_dir ( & self ) -> Option < & Path > {
447- match self {
448- Self :: File ( path) => path. parent ( ) . or_else ( || {
449- tracing:: warn!( "Error finding local app dir from source {path:?}" ) ;
450- None
451- } ) ,
452- _ => None ,
453- }
454- }
455-
456- async fn build ( & self ) -> anyhow:: Result < ( ) > {
457- match self {
458- Self :: File ( path) => spin_build:: build ( path, & [ ] ) . await ,
459- _ => Ok ( ( ) ) ,
460- }
461- }
462- }
463-
464- impl Display for AppSource {
465- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
466- match self {
467- AppSource :: None => write ! ( f, "<no source>" ) ,
468- AppSource :: File ( path) => write ! ( f, "local app {path:?}" ) ,
469- AppSource :: OciRegistry ( reference) => write ! ( f, "remote app {reference:?}" ) ,
470- AppSource :: Unresolvable ( s) => write ! ( f, "unknown app source: {s:?}" ) ,
471- }
472- }
473- }
474-
475419#[ cfg( test) ]
476420mod test {
421+ use crate :: commands:: up:: app_source:: AppSource ;
422+
477423 use super :: * ;
478424
479425 fn repo_path ( path : & str ) -> String {
0 commit comments