Rewrite porcelain handlers to use enum tuples of field structs instead of field structs #48

Closed
opened 2024-08-01 11:23:08 +00:00 by ryan · 1 comment
Owner

For instance, instead of:

enum WizardSubcommands {
    GenerateShardSecret {
        #[arg(long)]
        threshold: u8,
        #[arg(long)]
        max: u8,
        #[arg(long, default_value = "1")]
        keys_per_shard: u8,
        #[arg(long)]
        output: Option<PathBuf>,
    },
    BottomsUp {
        key_discovery: PathBuf,
        #[arg(long)]
        threshold: u8,
        #[arg(long)]
        output_shardfile: PathBuf,
        #[arg(long)]
        output_cert: PathBuf,
        #[arg(long, default_value = "Disaster Recovery")]
        user_id: String,
    },
}

it should be:

enum WizardSubcommands {
    GenerateShardSecret(GenerateShardSecret),
    BottomsUp(BottomsUp),
}

struct GenerateShardSecret {
    #[arg(long)]
    threshold: u8,
    #[arg(long)]
    max: u8,
    #[arg(long, default_value = "1")]
    keys_per_shard: u8,
    #[arg(long)]
    output: Option<PathBuf>,
}

struct BottomsUp {
    key_discovery: PathBuf,
    #[arg(long)]
    threshold: u8,
    #[arg(long)]
    output_shardfile: PathBuf,
    #[arg(long)]
    output_cert: PathBuf,
    #[arg(long, default_value = "Disaster Recovery")]
    user_id: String,
}

This way, subcommands can:

  1. be written in their own files, options and all
  2. have handle() functions that take structs instead of checks notes 5 arguments
For instance, instead of: ```rust enum WizardSubcommands { GenerateShardSecret { #[arg(long)] threshold: u8, #[arg(long)] max: u8, #[arg(long, default_value = "1")] keys_per_shard: u8, #[arg(long)] output: Option<PathBuf>, }, BottomsUp { key_discovery: PathBuf, #[arg(long)] threshold: u8, #[arg(long)] output_shardfile: PathBuf, #[arg(long)] output_cert: PathBuf, #[arg(long, default_value = "Disaster Recovery")] user_id: String, }, } ``` it should be: ```rust enum WizardSubcommands { GenerateShardSecret(GenerateShardSecret), BottomsUp(BottomsUp), } struct GenerateShardSecret { #[arg(long)] threshold: u8, #[arg(long)] max: u8, #[arg(long, default_value = "1")] keys_per_shard: u8, #[arg(long)] output: Option<PathBuf>, } struct BottomsUp { key_discovery: PathBuf, #[arg(long)] threshold: u8, #[arg(long)] output_shardfile: PathBuf, #[arg(long)] output_cert: PathBuf, #[arg(long, default_value = "Disaster Recovery")] user_id: String, } ``` This way, subcommands can: 1. be written in their own files, options and all 2. have handle() functions that take structs instead of *checks notes* 5 arguments
Author
Owner

done as of keyfork-v0.2.4

done as of keyfork-v0.2.4
ryan closed this issue 2024-08-11 21:47:26 +00:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: public/keyfork#48
No description provided.