1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::networks::{generate_actor_bundle, get_actor_bundles_metadata};
use std::path::PathBuf;

#[derive(Debug, clap::Subcommand)]
pub enum StateMigrationCommands {
    /// Generate a merged actor bundle from the hard-coded sources in forest
    ActorBundle {
        #[arg(default_value = "actor_bundles.car.zst")]
        output: PathBuf,
    },
    /// Generate actors metadata from required bundles list
    GenerateActorsMetadata,
}

impl StateMigrationCommands {
    pub async fn run(self) -> anyhow::Result<()> {
        match self {
            Self::ActorBundle { output } => {
                generate_actor_bundle(&output).await?;
                println!("Wrote the actors bundle to {}", output.display());
                Ok(())
            }
            Self::GenerateActorsMetadata => {
                let metadata = get_actor_bundles_metadata().await?;
                let metadata_json = serde_json::to_string_pretty(&metadata)?;
                println!("{}", metadata_json);

                Ok(())
            }
        }
    }
}