3
use smbcloud_ascapi_appgallery::{
4
AppInfoFields as AppGalleryInfoFields, FileType as AppGalleryFileType,
5
ImageOrientation as AppGalleryOrientation, LanguageFields as AppGalleryLanguageFields,
6
+ PhasedRelease as AppGalleryPhasedRelease, ReleaseTimeChange as AppGalleryReleaseTimeChange,
7
+ Submit as AppGallerySubmit,
8
};
9
use smbcloud_ascapi_aso::app::AppUpdateAttributes;
10
use smbcloud_ascapi_aso::app_info_localization::{
101
},
102
}
103
102
-// `Listings` carries the nested update command with its many text flags; boxing
103
-// a clap subcommand field is not possible.
104
+// The update commands carry many flags; boxing a clap subcommand field is not
105
+// possible.
106
#[allow(clippy::large_enum_variant)]
107
#[derive(Subcommand)]
108
enum AppGalleryCommand {
109
+ /// Look up the AppGallery app id for a package name.
110
+ AppId { package: String },
111
/// Localized listing text: name, description, brief and release notes.
112
Listings {
113
#[command(subcommand)]
114
command: AppGalleryListingsCommand,
115
},
112
- /// Look up the AppGallery app id for a package name.
113
- AppId { package: String },
114
- /// Basic information: privacy policy link and similar.
116
+ /// Basic information: privacy links, category, countries, price and flags.
117
Info {
118
#[command(subcommand)]
119
command: AppGalleryInfoCommand,
120
},
119
- /// Icon and screenshots for one language.
120
- Images {
121
+ /// Upload and bind files: icon, screenshots, videos, promo images,
122
+ /// certificates, VR assets, or the APK/AAB/RPK.
123
+ #[command(alias = "images")]
124
+ Files {
125
+ #[command(subcommand)]
126
+ command: AppGalleryFilesCommand,
127
+ },
128
+ /// Uploaded packages and whether they parsed.
129
+ Packages {
130
#[command(subcommand)]
122
- command: AppGalleryImagesCommand,
131
+ command: AppGalleryPackagesCommand,
132
+ },
133
+ /// Report whether the app depends on Google Mobile Services.
134
+ Gms {
135
+ app: String,
136
+ /// true if the app needs GMS, false if it runs without it.
137
+ #[arg(long, action = clap::ArgAction::Set)]
138
+ needs_gms: bool,
139
+ },
140
+ /// Submit the app for review. Once approved it goes live (at
141
+ /// --release-time if given). Check everything with --dry-run first.
142
+ Submit {
143
+ app: String,
144
+ /// yyyy-MM-ddTHH:mm:ss+HHMM; released right after approval when unset.
145
+ #[arg(long)]
146
+ release_time: Option<String>,
147
+ /// Note for the reviewer, 10-300 characters.
148
+ #[arg(long, conflicts_with = "remark_file")]
149
+ remark: Option<String>,
150
+ #[arg(long)]
151
+ remark_file: Option<PathBuf>,
152
+ #[command(flatten)]
153
+ phased: PhasedArgs,
154
+ },
155
+ /// Change a running phased release, or turn it into a full release.
156
+ PhasedRelease {
157
+ app: String,
158
+ /// Release to the entire network instead; ignores the other flags.
159
+ #[arg(long)]
160
+ to_full: bool,
161
+ /// SUSPEND or RELEASE.
162
+ #[arg(long)]
163
+ state: Option<String>,
164
+ #[command(flatten)]
165
+ phased: PhasedArgs,
166
+ },
167
+ /// Change when a version in Releasing state goes live.
168
+ ReleaseTime {
169
+ app: String,
170
+ #[arg(long, conflicts_with = "at", required_unless_present = "at")]
171
+ immediately: bool,
172
+ /// yyyy-MM-ddTHH:mm:ss+HHMM
173
+ #[arg(long)]
174
+ at: Option<String>,
175
},
176
}
177
178
+/// The phased-release window. Setting any of these on `submit` makes it a
179
+/// phased release, which needs a version already released.
180
+#[derive(clap::Args)]
181
+struct PhasedArgs {
182
+ /// yyyy-MM-ddTHH:mm:ss+HHMM
183
+ #[arg(long)]
184
+ phased_start: Option<String>,
185
+ /// yyyy-MM-ddTHH:mm:ss+HHMM
186
+ #[arg(long)]
187
+ phased_end: Option<String>,
188
+ /// 0.00-100.00, no percent sign.
189
+ #[arg(long)]
190
+ phased_percent: Option<String>,
191
+ /// Up to 500 characters.
192
+ #[arg(long)]
193
+ phased_description: Option<String>,
194
+}
195
+
196
+impl PhasedArgs {
197
+ fn into_release(self, state: Option<String>) -> Option<AppGalleryPhasedRelease> {
198
+ let any = self.phased_start.is_some()
199
+ || self.phased_end.is_some()
200
+ || self.phased_percent.is_some()
201
+ || self.phased_description.is_some()
202
+ || state.is_some();
203
+ any.then_some(AppGalleryPhasedRelease {
204
+ state,
205
+ phased_release_start_time: self.phased_start,
206
+ phased_release_end_time: self.phased_end,
207
+ phased_release_percent: self.phased_percent,
208
+ phased_release_description: self.phased_description,
209
+ })
210
+ }
211
+}
212
+
213
#[derive(Subcommand)]
214
enum AppGalleryInfoCommand {
128
- /// Set the privacy policy link (required by the API) and, optionally,
129
- /// the developer website and the privacy-rights and user-agreement URLs.
130
- /// Reads the privacy link back. With `--dry-run` nothing is sent.
215
+ /// Update basic information. The API needs --privacy-policy on every
216
+ /// call; every other flag is left unchanged when omitted. Reads the
217
+ /// privacy link back. With `--dry-run` nothing is sent.
218
Update {
219
app: String,
220
#[arg(long)]
221
privacy_policy: String,
222
+ /// Default language, e.g. en-US.
223
+ #[arg(long)]
224
+ default_lang: Option<String>,
225
+ /// Level-2 category id, e.g. 10000000 (Tools).
226
+ #[arg(long)]
227
+ category: Option<u32>,
228
+ /// Level-3 category (tag) id, e.g. 15000005.
229
+ #[arg(long)]
230
+ category_tag: Option<u32>,
231
+ /// Comma-separated country/region codes. Leave CN out to keep the
232
+ /// app off the Chinese mainland.
233
+ #[arg(long)]
234
+ publish_country: Option<String>,
235
+ /// 1 free, 0 paid (needs --price and --price-detail). Fixed after release.
236
+ #[arg(long)]
237
+ is_free: Option<u8>,
238
+ /// {"countryCode":"price"}
239
+ #[arg(long)]
240
+ price: Option<String>,
241
+ /// JSON array of {country, currency, price}.
242
+ #[arg(long)]
243
+ price_detail: Option<String>,
244
+ /// Comma-separated in-app purchase types (1 activation ... 8 membership).
245
+ #[arg(long)]
246
+ tariff_type: Option<String>,
247
#[arg(long)]
248
developer_website: Option<String>,
137
- /// URL where users can view, change and delete their personal data.
249
+ /// URL where users view, change and delete their personal data.
250
#[arg(long)]
251
privacy_rights_url: Option<String>,
252
#[arg(long)]
253
user_agreement_url: Option<String>,
254
+ /// JSON, e.g. [{"deviceType":4,"appAdapters":"4,5"}] (4 phone, 5 tablet).
255
+ #[arg(long)]
256
+ device_types: Option<String>,
257
+ /// 0 or 1.
258
+ #[arg(long)]
259
+ forced_update: Option<u8>,
260
+ /// 0 or 1: let AppGallery fetch the package from the Internet.
261
+ #[arg(long)]
262
+ auto_download: Option<u8>,
263
+ /// 0 or 1.
264
+ #[arg(long)]
265
+ family_share: Option<u8>,
266
+ /// 0 or 1; the API defaults to 1.
267
+ #[arg(long)]
268
+ encrypted: Option<u8>,
269
+ /// Games: 1 standalone, 2 online.
270
+ #[arg(long)]
271
+ net_type: Option<u8>,
272
+ /// Games: 0 or 1.
273
+ #[arg(long)]
274
+ web_game: Option<u8>,
275
+ /// Games: publication approval number.
276
+ #[arg(long)]
277
+ publication_number: Option<String>,
278
+ /// Games, China only: Internet culture operation license number.
279
+ #[arg(long)]
280
+ culture_record_number: Option<String>,
281
+ /// Trustlisted developers only.
282
+ #[arg(long)]
283
+ developer_name_cn: Option<String>,
284
+ /// Trustlisted developers only.
285
+ #[arg(long)]
286
+ developer_name_en: Option<String>,
287
},
288
}
289
290
#[derive(Clone, Copy, ValueEnum)]
146
-enum CliAppGalleryImageKind {
291
+enum CliAppGalleryFileType {
292
Icon,
293
Screenshots,
294
+ IntroVideo,
295
+ PromoVideo,
296
+ PromoImage,
297
+ Package,
298
+ AgentCertificate,
299
+ ElectronicCertificate,
300
+ CultureLicenseScreenshot,
301
+ CultureLicense,
302
+ VrCover,
303
+ VrScreenshots,
304
+ VrPromoImage,
305
+ VrCoverLayered,
306
+ #[value(name = "vr-promo-4x3")]
307
+ VrPromo4x3,
308
+ #[value(name = "vr-promo-1x1")]
309
+ VrPromo1x1,
310
+ VrPanorama,
311
+}
312
+
313
+impl From<CliAppGalleryFileType> for AppGalleryFileType {
314
+ fn from(value: CliAppGalleryFileType) -> Self {
315
+ match value {
316
+ CliAppGalleryFileType::Icon => Self::Icon,
317
+ CliAppGalleryFileType::Screenshots => Self::Screenshots,
318
+ CliAppGalleryFileType::IntroVideo => Self::IntroVideo,
319
+ CliAppGalleryFileType::PromoVideo => Self::PromoVideo,
320
+ CliAppGalleryFileType::PromoImage => Self::PromoImage,
321
+ CliAppGalleryFileType::Package => Self::Package,
322
+ CliAppGalleryFileType::AgentCertificate => Self::AgentCertificate,
323
+ CliAppGalleryFileType::ElectronicCertificate => Self::ElectronicCertificate,
324
+ CliAppGalleryFileType::CultureLicenseScreenshot => Self::CultureLicenseScreenshot,
325
+ CliAppGalleryFileType::CultureLicense => Self::CultureLicense,
326
+ CliAppGalleryFileType::VrCover => Self::VrCover,
327
+ CliAppGalleryFileType::VrScreenshots => Self::VrScreenshots,
328
+ CliAppGalleryFileType::VrPromoImage => Self::VrPromoImage,
329
+ CliAppGalleryFileType::VrCoverLayered => Self::VrCoverLayered,
330
+ CliAppGalleryFileType::VrPromo4x3 => Self::VrPromo4x3,
331
+ CliAppGalleryFileType::VrPromo1x1 => Self::VrPromo1x1,
332
+ CliAppGalleryFileType::VrPanorama => Self::VrPanorama,
333
+ }
334
+ }
335
}
336
337
#[derive(Clone, Copy, ValueEnum)]
340
Landscape,
341
}
342
343
+impl From<CliAppGalleryOrientation> for AppGalleryOrientation {
344
+ fn from(value: CliAppGalleryOrientation) -> Self {
345
+ match value {
346
+ CliAppGalleryOrientation::Portrait => Self::Portrait,
347
+ CliAppGalleryOrientation::Landscape => Self::Landscape,
348
+ }
349
+ }
350
+}
351
+
352
#[derive(Subcommand)]
158
-enum AppGalleryImagesCommand {
159
- /// Upload an icon (one file) or screenshots (in display order) and bind
160
- /// them to a language. Sent with chineseMainlandFlag=0. With `--dry-run`
161
- /// it lists each file's size and SHA-256 and sends nothing.
353
+enum AppGalleryFilesCommand {
354
+ /// Upload files of one type, in display order, and bind them. Images
355
+ /// and videos need --lang; that language's text is checked and written
356
+ /// back if binding cleared it. With `--dry-run` it lists each file's size
357
+ /// and SHA-256 and sends nothing.
358
Upload {
359
app: String,
360
+ #[arg(long = "type", alias = "kind", value_enum)]
361
+ file_type: CliAppGalleryFileType,
362
#[arg(long)]
165
- lang: String,
166
- #[arg(long, value_enum)]
167
- kind: CliAppGalleryImageKind,
168
- /// Required for screenshots.
363
+ lang: Option<String>,
364
+ /// Screenshots: portrait or landscape.
365
#[arg(long, value_enum)]
366
orientation: Option<CliAppGalleryOrientation>,
171
- /// PNG or JPEG files.
367
+ /// Videos: portrait or landscape.
368
+ #[arg(long, value_enum)]
369
+ video_orientation: Option<CliAppGalleryOrientation>,
370
+ /// Packages: sensitive permission description.
371
+ #[arg(long)]
372
+ sensitive_permission_desc: Option<String>,
373
+ /// Device type for visual assets on a multi-device app (4 phone).
374
+ #[arg(long)]
375
+ device_type: Option<u8>,
376
+ /// Distribute the package to the Chinese mainland. Off by default.
377
+ #[arg(long)]
378
+ chinese_mainland: bool,
379
+ /// The files. Videos alternate with their posters: video, poster, ...
380
#[arg(required = true)]
381
files: Vec<PathBuf>,
382
},
383
}
384
385
+#[derive(Subcommand)]
386
+enum AppGalleryPackagesCommand {
387
+ /// Packages uploaded for the app, newest first.
388
+ List {
389
+ app: String,
390
+ /// First record, from 1.
391
+ #[arg(long)]
392
+ from: Option<u32>,
393
+ /// Up to 100 (the API's default is 10).
394
+ #[arg(long)]
395
+ max: Option<u32>,
396
+ },
397
+ /// Parse status of packages: 0 normal, 1 parsing, 2 failed.
398
+ Status {
399
+ app: String,
400
+ /// Package ids (pkgVersion from `packages list` or the upload).
401
+ #[arg(required = true)]
402
+ pkg_ids: Vec<String>,
403
+ },
404
+}
405
+
406
#[derive(Subcommand)]
407
enum AppGalleryListingsCommand {
179
- /// App info and every language's text, or one language's. `APP` is the
180
- /// numeric app id or the package name.
408
+ /// App info and every language's text and assets, or one language's.
409
+ /// `APP` is the numeric app id or the package name.
410
List {
411
app: String,
412
#[arg(long)]
444
#[arg(long, value_parser = clap::value_parser!(u8).range(1..=3))]
445
release_type: Option<u8>,
446
},
447
+ /// Delete one language's listing. The default language cannot be deleted.
448
+ Delete {
449
+ app: String,
450
+ #[arg(long)]
451
+ lang: String,
452
+ },
453
}
454
455
#[derive(Subcommand)]
680
let client = appgallery::appgallery_client(service_account, client_id)
681
.map_err(|e| anyhow::anyhow!(e))?;
682
let fail = |e: String| anyhow::anyhow!(e);
683
+ let flag = |label: &str, dry: bool| {
684
+ if dry {
685
+ println!("# dry run: nothing was sent; {label}:");
686
+ }
687
+ };
688
match command {
689
AppGalleryCommand::AppId { package } => print_json(
690
&client
696
AppGalleryInfoCommand::Update {
697
app,
698
privacy_policy,
699
+ default_lang,
700
+ category,
701
+ category_tag,
702
+ publish_country,
703
+ is_free,
704
+ price,
705
+ price_detail,
706
+ tariff_type,
707
developer_website,
708
privacy_rights_url,
709
user_agreement_url,
710
+ device_types,
711
+ forced_update,
712
+ auto_download,
713
+ family_share,
714
+ encrypted,
715
+ net_type,
716
+ web_game,
717
+ publication_number,
718
+ culture_record_number,
719
+ developer_name_cn,
720
+ developer_name_en,
721
} => {
722
+ let device_types = device_types
723
+ .map(|json| serde_json::from_str(&json))
724
+ .transpose()
725
+ .context("--device-types must be JSON")?;
726
let fields = AppGalleryInfoFields {
727
privacy_policy,
728
+ default_lang,
729
+ child_type: category,
730
+ grand_child_type: category_tag,
731
+ app_net_type: net_type,
732
+ is_free,
733
+ price,
734
+ price_detail,
735
+ publish_country,
736
+ is_app_forced_update: forced_update,
737
+ hispace_auto_down: auto_download,
738
+ app_tariff_type: tariff_type,
739
+ publication_number,
740
+ culture_record_number,
741
+ developer_name_cn,
742
+ developer_name_en,
743
developer_website,
744
+ family_share_tag: family_share,
745
+ device_types,
746
+ web_game_flag: web_game,
747
privacy_rights_url,
748
user_agreement_url,
749
+ encrypted,
750
};
751
let result = appgallery::update_basic_info(&client, &app, fields, None, dry_run)
752
.await
753
.map_err(fail)?;
472
- if result.dry_run {
473
- println!("# dry run: nothing was sent; body that would be sent:");
474
- }
754
+ flag("body that would be sent", result.dry_run);
755
print_json(&result)
756
}
757
},
478
- AppGalleryCommand::Images { command } => match command {
479
- AppGalleryImagesCommand::Upload {
758
+ AppGalleryCommand::Files { command } => match command {
759
+ AppGalleryFilesCommand::Upload {
760
app,
761
+ file_type,
762
lang,
482
- kind,
763
orientation,
764
+ video_orientation,
765
+ sensitive_permission_desc,
766
+ device_type,
767
+ chinese_mainland,
768
files,
769
} => {
486
- let kind = match kind {
487
- CliAppGalleryImageKind::Icon => AppGalleryFileType::Icon,
488
- CliAppGalleryImageKind::Screenshots => AppGalleryFileType::Screenshots,
770
+ let options = appgallery::UploadOptions {
771
+ lang,
772
+ image_orientation: orientation.map(Into::into),
773
+ video_orientation: video_orientation.map(Into::into),
774
+ sensitive_permission_desc,
775
+ device_type,
776
+ chinese_mainland,
777
};
490
- let orientation = orientation.map(|o| match o {
491
- CliAppGalleryOrientation::Portrait => AppGalleryOrientation::Portrait,
492
- CliAppGalleryOrientation::Landscape => AppGalleryOrientation::Landscape,
493
- });
494
- let result = appgallery::upload_images(
778
+ let result = appgallery::upload_files(
779
&client,
780
&app,
497
- &lang,
498
- kind,
499
- orientation,
781
+ file_type.into(),
782
&files,
783
+ &options,
784
dry_run,
785
)
786
.await
787
.map_err(fail)?;
505
- if result.dry_run {
506
- println!("# dry run: nothing was uploaded; files that would be sent:");
507
- }
788
+ flag("files that would be uploaded", result.dry_run);
789
print_json(&result)
790
}
791
},
792
+ AppGalleryCommand::Packages { command } => match command {
793
+ AppGalleryPackagesCommand::List { app, from, max } => print_json(
794
+ &appgallery::package_list(&client, &app, from, max)
795
+ .await
796
+ .map_err(fail)?,
797
+ ),
798
+ AppGalleryPackagesCommand::Status { app, pkg_ids } => print_json(
799
+ &appgallery::package_status(&client, &app, &pkg_ids)
800
+ .await
801
+ .map_err(fail)?,
802
+ ),
803
+ },
804
+ AppGalleryCommand::Gms { app, needs_gms } => {
805
+ let result = appgallery::set_gms_dependency(&client, &app, needs_gms, dry_run)
806
+ .await
807
+ .map_err(fail)?;
808
+ flag("body that would be sent", result.dry_run);
809
+ print_json(&result)
810
+ }
811
+ AppGalleryCommand::Submit {
812
+ app,
813
+ release_time,
814
+ remark,
815
+ remark_file,
816
+ phased,
817
+ } => {
818
+ let options = AppGallerySubmit {
819
+ release_time,
820
+ remark: text_arg(remark, remark_file, "--remark-file")?,
821
+ phased: phased.into_release(None),
822
+ };
823
+ let result = appgallery::submit(&client, &app, options, dry_run)
824
+ .await
825
+ .map_err(fail)?;
826
+ flag("submission that would be sent", result.dry_run);
827
+ print_json(&result)
828
+ }
829
+ AppGalleryCommand::PhasedRelease {
830
+ app,
831
+ to_full,
832
+ state,
833
+ phased,
834
+ } => {
835
+ let release = phased.into_release(state).unwrap_or_default();
836
+ let result =
837
+ appgallery::update_phased_release(&client, &app, release, to_full, dry_run)
838
+ .await
839
+ .map_err(fail)?;
840
+ flag("body that would be sent", result.dry_run);
841
+ print_json(&result)
842
+ }
843
+ AppGalleryCommand::ReleaseTime {
844
+ app,
845
+ immediately,
846
+ at,
847
+ } => {
848
+ let change = match (immediately, at) {
849
+ (true, _) => AppGalleryReleaseTimeChange::Immediately,
850
+ (false, Some(at)) => AppGalleryReleaseTimeChange::At(at),
851
+ (false, None) => anyhow::bail!("pass --immediately or --at"),
852
+ };
853
+ let result = appgallery::update_release_time(&client, &app, change, dry_run)
854
+ .await
855
+ .map_err(fail)?;
856
+ flag("body that would be sent", result.dry_run);
857
+ print_json(&result)
858
+ }
859
AppGalleryCommand::Listings { command } => match command {
860
AppGalleryListingsCommand::List { app, lang } => print_json(
861
&appgallery::read_listings(&client, &app, lang.as_deref())
890
appgallery::update_language(&client, &app, fields, release_type, dry_run)
891
.await
892
.map_err(fail)?;
545
- if result.dry_run {
546
- println!("# dry run: nothing was sent; body that would be sent:");
547
- }
893
+ flag("body that would be sent", result.dry_run);
894
+ print_json(&result)
895
+ }
896
+ AppGalleryListingsCommand::Delete { app, lang } => {
897
+ let result = appgallery::delete_language(&client, &app, &lang, dry_run)
898
+ .await
899
+ .map_err(fail)?;
900
print_json(&result)
901
}
902
},