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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use clap::Parser;
use std::process::ExitCode;
mod block;
mod commands;
mod domain;
mod export;
mod import;
mod logo;
mod publish;
mod pwd;
mod remove;
mod serve;
mod util;
use commands::*;
use util::*;
use crate::domain::DomainCommands;
fn main() -> ExitCode {
let cli = Cli::parse();
let outcome = match &cli.command {
Commands::Domain(domain_args) => {
match &domain_args.command {
Some(DomainCommands::List(list_args)) => {
smol::block_on(async { domain::list_domains(list_args).await })
}
None => {
// Generate a new subspace keypair and present it to the user
domain::generate_domain(domain_args);
Ok(())
}
}
}
Commands::Publish(publish_args) => {
// Verify a domain keypair, then recurse through the given filesystem location,
// writing entries to that domain for any files encountered.
//
// Skip files matching globs in ".nopublish" files, and the ".nopublish" files themselves.
smol::block_on(async {
publish::publish(publish_args).await?;
yay("publishing complete!").await;
Ok(())
})
}
Commands::Block(block_args) => {
// Forget the given subspace ID from persistent storage.
// And add it to a blocklist, which for now could maybe just be a line delimited text file.
smol::block_on(async {
block::block(block_args).await?;
yay("domain blocked").await;
Ok(())
})
}
Commands::Remove(remove_args) => {
// Forget the given subspace ID from persistent storage without adding it to a blocklist.
smol::block_on(async {
remove::remove(remove_args).await?;
yay("domain(s) removed").await;
Ok(())
})
}
Commands::Import(import_args) => {
// Import the contents of a drop into the persistent store.
smol::block_on(async {
import::import_sneak(import_args).await?;
yay(&format!(
"successfully imported from {}",
import_args.src.to_string_lossy()
))
.await;
Ok(())
})
}
Commands::Export(export_args) => {
// Export the contents of the persistent store into a willow drop.
smol::block_on(async {
let dest = export::export_sneak(export_args).await?;
yay(&format!("sneak exported to {}", dest.to_string_lossy())).await;
Ok(())
})
}
Commands::Serve(serve_args) => {
smol::block_on(async { serve::start_server(serve_args).await })
}
Commands::Pwd(args) => smol::block_on(async { pwd::pwd(args).await }),
};
match outcome {
Ok(()) => ExitCode::SUCCESS,
Err(err) => smol::block_on(async {
oh_no(&format!("{}", err)).await;
ExitCode::FAILURE
}),
}
}