1
1
// This is pretty much a copy of the wkg wit subcommand adapted for wash
2
2
use std:: path:: PathBuf ;
3
3
4
- use anyhow:: Ok ;
4
+ use anyhow:: Context ;
5
5
use clap:: { Args , Subcommand } ;
6
6
use wash_lib:: {
7
- build:: monkey_patch_fetch_logging,
7
+ build:: { load_lock_file , monkey_patch_fetch_logging} ,
8
8
cli:: { CommandOutput , CommonPackageArgs } ,
9
+ parser:: load_config,
9
10
} ;
10
11
use wasm_pkg_client:: { PublishOpts , Registry } ;
11
- use wasm_pkg_core:: {
12
- lock:: LockFile ,
13
- wit:: { self , OutputType } ,
14
- } ;
12
+ use wasm_pkg_core:: wit:: { self , OutputType } ;
15
13
16
14
/// Commands for interacting with wit
17
15
#[ derive( Debug , Subcommand , Clone ) ]
@@ -25,7 +23,7 @@ pub enum WitCommand {
25
23
/// dependencies and write them to the `deps` directory along with a lock file. If no lock file
26
24
/// exists, it will fetch all dependencies. If a lock file exists, it will fetch any
27
25
/// dependencies that are not in the lock file and update the lock file.
28
- Fetch ( FetchArgs ) ,
26
+ Deps ( DepsArgs ) ,
29
27
/// Publish a WIT package to a registry. This will automatically infer the package name from the
30
28
/// WIT package.
31
29
Publish ( PublishArgs ) ,
@@ -35,7 +33,7 @@ impl WitCommand {
35
33
pub async fn run ( self ) -> anyhow:: Result < CommandOutput > {
36
34
match self {
37
35
WitCommand :: Build ( args) => args. run ( ) . await ,
38
- WitCommand :: Fetch ( args) => args. run ( ) . await ,
36
+ WitCommand :: Deps ( args) => args. run ( ) . await ,
39
37
WitCommand :: Publish ( args) => args. run ( ) . await ,
40
38
}
41
39
}
@@ -54,10 +52,14 @@ pub struct BuildArgs {
54
52
55
53
#[ clap( flatten) ]
56
54
pub common : CommonPackageArgs ,
55
+
56
+ /// Path to the wasmcloud.toml file or parent folder to use for building
57
+ #[ clap( short = 'p' , long = "config-path" ) ]
58
+ config_path : Option < PathBuf > ,
57
59
}
58
60
59
61
#[ derive( Debug , Args , Clone ) ]
60
- pub struct FetchArgs {
62
+ pub struct DepsArgs {
61
63
/// The directory containing the WIT files to fetch dependencies for.
62
64
#[ clap( short = 'd' , long = "wit-dir" , default_value = "wit" ) ]
63
65
pub dir : PathBuf ,
@@ -69,6 +71,10 @@ pub struct FetchArgs {
69
71
70
72
#[ clap( flatten) ]
71
73
pub common : CommonPackageArgs ,
74
+
75
+ /// Path to the wasmcloud.toml file or parent folder to use for building
76
+ #[ clap( short = 'p' , long = "config-path" ) ]
77
+ config_path : Option < PathBuf > ,
72
78
}
73
79
74
80
#[ derive( Args , Debug , Clone ) ]
@@ -87,8 +93,15 @@ pub struct PublishArgs {
87
93
impl BuildArgs {
88
94
pub async fn run ( self ) -> anyhow:: Result < CommandOutput > {
89
95
let client = self . common . get_client ( ) . await ?;
90
- let wkg_config = wasm_pkg_core:: config:: Config :: load ( ) . await ?;
91
- let mut lock_file = LockFile :: load ( false ) . await ?;
96
+ // Attempt to load wasmcloud.toml. If it doesn't work, attempt to load wkg.toml
97
+ let wkg_config = if let Ok ( proj) = load_config ( self . config_path , Some ( true ) ) . await {
98
+ proj. package_config
99
+ } else {
100
+ wasm_pkg_core:: config:: Config :: load ( ) . await ?
101
+ } ;
102
+ let mut lock_file =
103
+ load_lock_file ( std:: env:: current_dir ( ) . context ( "failed to get current directory" ) ?)
104
+ . await ?;
92
105
let ( pkg_ref, version, bytes) =
93
106
wit:: build_package ( & wkg_config, self . dir , & mut lock_file, client) . await ?;
94
107
let output_path = if let Some ( path) = self . output_file {
@@ -118,11 +131,18 @@ impl BuildArgs {
118
131
}
119
132
}
120
133
121
- impl FetchArgs {
134
+ impl DepsArgs {
122
135
pub async fn run ( self ) -> anyhow:: Result < CommandOutput > {
123
136
let client = self . common . get_client ( ) . await ?;
124
- let wkg_config = wasm_pkg_core:: config:: Config :: load ( ) . await ?;
125
- let mut lock_file = LockFile :: load ( false ) . await ?;
137
+ // Attempt to load wasmcloud.toml. If it doesn't work, attempt to load wkg.toml
138
+ let wkg_config = if let Ok ( proj) = load_config ( self . config_path , Some ( true ) ) . await {
139
+ proj. package_config
140
+ } else {
141
+ wasm_pkg_core:: config:: Config :: load ( ) . await ?
142
+ } ;
143
+ let mut lock_file =
144
+ load_lock_file ( std:: env:: current_dir ( ) . context ( "failed to get current directory" ) ?)
145
+ . await ?;
126
146
monkey_patch_fetch_logging ( wkg_config, self . dir , & mut lock_file, client) . await ?;
127
147
// Now write out the lock file since everything else succeeded
128
148
lock_file. write ( ) . await ?;
0 commit comments