Prevent CLI tool from reading config when it's not needed
This commit is contained in:
parent
2747f3eafe
commit
26763d9f5d
3 changed files with 70 additions and 62 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -2202,9 +2202,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.26"
|
version = "1.0.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
|
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
@ -2965,9 +2965,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.69"
|
version = "1.0.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb"
|
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -3368,9 +3368,9 @@ checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
|
|
24
README.md
24
README.md
|
@ -110,18 +110,6 @@ GET /api/v1/statuses/{status_id}/signature
|
||||||
|
|
||||||
## CLI commands
|
## CLI commands
|
||||||
|
|
||||||
Delete profile:
|
|
||||||
|
|
||||||
```
|
|
||||||
mitractl delete-profile -i 55a3005f-f293-4168-ab70-6ab09a879679
|
|
||||||
```
|
|
||||||
|
|
||||||
Delete post:
|
|
||||||
|
|
||||||
```
|
|
||||||
mitractl delete-post -i 55a3005f-f293-4168-ab70-6ab09a879679
|
|
||||||
```
|
|
||||||
|
|
||||||
Generate invite code:
|
Generate invite code:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -134,6 +122,18 @@ List generated invites:
|
||||||
mitractl list-invite-codes
|
mitractl list-invite-codes
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Delete profile:
|
||||||
|
|
||||||
|
```
|
||||||
|
mitractl delete-profile -i 55a3005f-f293-4168-ab70-6ab09a879679
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete post:
|
||||||
|
|
||||||
|
```
|
||||||
|
mitractl delete-post -i 55a3005f-f293-4168-ab70-6ab09a879679
|
||||||
|
```
|
||||||
|
|
||||||
Generate ethereum address:
|
Generate ethereum address:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -22,13 +22,26 @@ struct Opts {
|
||||||
|
|
||||||
#[derive(Clap)]
|
#[derive(Clap)]
|
||||||
enum SubCommand {
|
enum SubCommand {
|
||||||
DeleteProfile(DeleteProfile),
|
GenerateEthereumAddress(GenerateEthereumAddress),
|
||||||
DeletePost(DeletePost),
|
|
||||||
GenerateInviteCode(GenerateInviteCode),
|
GenerateInviteCode(GenerateInviteCode),
|
||||||
ListInviteCodes(ListInviteCodes),
|
ListInviteCodes(ListInviteCodes),
|
||||||
GenerateEthereumAddress(GenerateEthereumAddress),
|
DeleteProfile(DeleteProfile),
|
||||||
|
DeletePost(DeletePost),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate ethereum address
|
||||||
|
#[derive(Clap)]
|
||||||
|
struct GenerateEthereumAddress;
|
||||||
|
|
||||||
|
/// Generate invite code
|
||||||
|
#[derive(Clap)]
|
||||||
|
struct GenerateInviteCode;
|
||||||
|
|
||||||
|
/// List invite codes
|
||||||
|
#[derive(Clap)]
|
||||||
|
struct ListInviteCodes;
|
||||||
|
|
||||||
/// Delete profile
|
/// Delete profile
|
||||||
#[derive(Clap)]
|
#[derive(Clap)]
|
||||||
struct DeleteProfile {
|
struct DeleteProfile {
|
||||||
|
@ -43,52 +56,11 @@ struct DeletePost {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate invite code
|
|
||||||
#[derive(Clap)]
|
|
||||||
struct GenerateInviteCode { }
|
|
||||||
|
|
||||||
/// List invite codes
|
|
||||||
#[derive(Clap)]
|
|
||||||
struct ListInviteCodes { }
|
|
||||||
|
|
||||||
/// Generate ethereum address
|
|
||||||
#[derive(Clap)]
|
|
||||||
struct GenerateEthereumAddress { }
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let config = config::parse_config();
|
|
||||||
configure_logger();
|
|
||||||
let db_pool = create_pool(&config.database_url);
|
|
||||||
apply_migrations(&db_pool).await;
|
|
||||||
let db_client = &mut **get_database_client(&db_pool).await.unwrap();
|
|
||||||
let opts: Opts = Opts::parse();
|
let opts: Opts = Opts::parse();
|
||||||
|
|
||||||
match opts.subcmd {
|
match opts.subcmd {
|
||||||
SubCommand::DeleteProfile(subopts) => {
|
|
||||||
let deletion_queue = delete_profile(db_client, &subopts.id).await.unwrap();
|
|
||||||
deletion_queue.process(&config).await;
|
|
||||||
println!("profile deleted");
|
|
||||||
},
|
|
||||||
SubCommand::DeletePost(subopts) => {
|
|
||||||
let deletion_queue = delete_post(db_client, &subopts.id).await.unwrap();
|
|
||||||
deletion_queue.process(&config).await;
|
|
||||||
println!("post deleted");
|
|
||||||
},
|
|
||||||
SubCommand::GenerateInviteCode(_) => {
|
|
||||||
let invite_code = create_invite_code(db_client).await.unwrap();
|
|
||||||
println!("generated invite code: {}", invite_code);
|
|
||||||
},
|
|
||||||
SubCommand::ListInviteCodes(_) => {
|
|
||||||
let invite_codes = get_invite_codes(db_client).await.unwrap();
|
|
||||||
if invite_codes.is_empty() {
|
|
||||||
println!("no invite codes found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for code in invite_codes {
|
|
||||||
println!("{}", code);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
SubCommand::GenerateEthereumAddress(_) => {
|
SubCommand::GenerateEthereumAddress(_) => {
|
||||||
let (private_key, address) = generate_ethereum_address();
|
let (private_key, address) = generate_ethereum_address();
|
||||||
println!(
|
println!(
|
||||||
|
@ -96,5 +68,41 @@ async fn main() {
|
||||||
address, private_key,
|
address, private_key,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
subcmd => {
|
||||||
|
// Other commands require initialized app
|
||||||
|
let config = config::parse_config();
|
||||||
|
configure_logger();
|
||||||
|
let db_pool = create_pool(&config.database_url);
|
||||||
|
apply_migrations(&db_pool).await;
|
||||||
|
let db_client = &mut **get_database_client(&db_pool).await.unwrap();
|
||||||
|
|
||||||
|
match subcmd {
|
||||||
|
SubCommand::GenerateInviteCode(_) => {
|
||||||
|
let invite_code = create_invite_code(db_client).await.unwrap();
|
||||||
|
println!("generated invite code: {}", invite_code);
|
||||||
|
},
|
||||||
|
SubCommand::ListInviteCodes(_) => {
|
||||||
|
let invite_codes = get_invite_codes(db_client).await.unwrap();
|
||||||
|
if invite_codes.is_empty() {
|
||||||
|
println!("no invite codes found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for code in invite_codes {
|
||||||
|
println!("{}", code);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SubCommand::DeleteProfile(subopts) => {
|
||||||
|
let deletion_queue = delete_profile(db_client, &subopts.id).await.unwrap();
|
||||||
|
deletion_queue.process(&config).await;
|
||||||
|
println!("profile deleted");
|
||||||
|
},
|
||||||
|
SubCommand::DeletePost(subopts) => {
|
||||||
|
let deletion_queue = delete_post(db_client, &subopts.id).await.unwrap();
|
||||||
|
deletion_queue.process(&config).await;
|
||||||
|
println!("post deleted");
|
||||||
|
},
|
||||||
|
_ => panic!(),
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue