Skip to content

Commit 3ce67c6

Browse files
committed
chore: flesh out init command; create data and config directories
1 parent 7c5e479 commit 3ce67c6

File tree

10 files changed

+153
-6
lines changed

10 files changed

+153
-6
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,8 @@ rust-project.json
131131
.cache
132132

133133
# Flamegraph
134-
*.svg
134+
*.svg
135+
136+
# Data and config directories
137+
/data
138+
/config

Cargo.toml

+23
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
[workspace]
22
members = ["horizon_cli", "horizon_common", "horizon_registry"]
3+
4+
[workspace.dependencies]
5+
clap = { version = "4.5", features = [
6+
"derive",
7+
"cargo",
8+
"wrap_help",
9+
"unicode",
10+
"string",
11+
"unstable-styles",
12+
] }
13+
14+
# tracing and error reporting dependencies
15+
color-eyre = { version = "0.6.3" }
16+
thiserror = { version = "2.0" }
17+
18+
# async dependencies
19+
tokio = { version = "1.43", features = ["rt-multi-thread", "fs"] }
20+
tokio-util = "0.7.12"
21+
22+
# app initialization dependencies
23+
lazy_static = "1.5"
24+
config = "0.15"
25+
directories = "6.0"

horizon_cli/Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
clap = { version = "4.5.32", features = ["derive", "env"] }
7+
clap.workspace = true
8+
tokio.workspace = true
9+
config.workspace = true
10+
color-eyre.workspace = true
11+
lazy_static.workspace = true
12+
directories.workspace = true
13+
14+
horizon_common = { path = "../horizon_common" }

horizon_cli/src/commands.rs

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
use clap::{Parser, Subcommand};
22

3+
/**
4+
horizon init # Initializes the Horizon environment locally
5+
6+
horizon list-gpus # Lists available GPUs in the Horizon marketplace
7+
horizon rent <gpu_id> --duration <hours> [--price <price>] # Rent a GPU for a specified duration
8+
horizon submit-job <gpu_id> --job <job_file> # Submit a job for execution on a specified GPU
9+
horizon bid <gpu_id> --price <price> # Place a bid for a GPU rental
10+
horizon auction start <gpu_id> --duration <duration> # Start an auction for a GPU
11+
horizon auction end <gpu_id> # End an auction for a GPU
12+
horizon status <job_id> # Retrieve the status of a job submitted to the marketplace
13+
horizon cancel-job <job_id> # Cancel a job in progress
14+
15+
horizon config --set <key> <value> # Set a configuration option (e.g., price limits, security keys)
16+
horizon config --get <key> # Retrieve a configuration value
17+
18+
horizon network status # Check the status of the Horizon network and nodes
19+
horizon network connect <node_id> # Connect to a specific node in the network
20+
horizon network disconnect <node_id> # Disconnect from a node in the network
21+
22+
horizon marketplace sync # Synchronize local data with the decentralized GPU marketplace
23+
horizon marketplace update # Update local GPU listings from the marketplace
24+
25+
horizon register-gpu --gpu-id <gpu_id> --gpu-type <type> --price <price> # Register a GPU for rental
26+
horizon deregister-gpu <gpu_id> # Deregister a GPU from the marketplace
27+
28+
horizon explore <gpu_id> [--filter <json_path>] # Interactively explore the details of a GPU
29+
30+
horizon logs # Display logs for Horizon operations and node status
31+
horizon logs clear # Clear the local logs
32+
33+
horizon version # Displays the Horizon CLI version
34+
horizon <command> --help # Shows help for a specific command
35+
*/
36+
337
#[derive(Parser)]
438
#[clap(version, name = "horizon", long_about = None)]
539
pub struct Cli {

horizon_cli/src/job_cmds.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::env;
2+
use std::path::PathBuf;
3+
4+
use lazy_static::lazy_static;
5+
6+
use horizon_common::HorizonCliState;
7+
8+
// get directories; default to ./data and ./config if env vars don't exist or aren't set
9+
// otherwise get HORIZON_DATA_DIRECTORY and HORIZON_CONFIG_DIRECTORY from env vars
10+
11+
lazy_static! {
12+
static ref HORIZON_DATA_DIRECTORY: PathBuf = {
13+
match env::var("HORIZON_DATA_DIRECTORY") {
14+
Ok(val) => PathBuf::from(val),
15+
Err(_) => PathBuf::from("./data"),
16+
}
17+
};
18+
static ref HORIZON_CONFIG_DIRECTORY: PathBuf = {
19+
match env::var("HORIZON_CONFIG_DIRECTORY") {
20+
Ok(val) => PathBuf::from(val),
21+
Err(_) => PathBuf::from("./config"),
22+
}
23+
};
24+
}
25+
26+
#[derive(Debug)]
27+
pub struct JobCommand {}
28+
29+
impl JobCommand {
30+
pub async fn init_command() {
31+
let state = HorizonCliState::new(
32+
HORIZON_DATA_DIRECTORY.to_path_buf(),
33+
HORIZON_CONFIG_DIRECTORY.to_path_buf(),
34+
);
35+
36+
state.init_data_folder().await;
37+
state.init_config_folder().await;
38+
}
39+
}

horizon_cli/src/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
pub mod commands;
2+
pub mod job_cmds;
23

34
use clap::Parser;
45
use commands::{Cli, Command};
56

6-
fn main() {
7+
use color_eyre::eyre::Report;
8+
use job_cmds::JobCommand;
9+
10+
#[tokio::main]
11+
async fn main() -> Result<(), Report> {
712
let cli = Cli::parse();
813

914
match cli.cmd {
1015
Command::Init => {
11-
// TODO: How do we want to manage local configuration? Initialization of a toml with
12-
// mappings? Confy crate? Other ideas/suggestions?
13-
todo!()
16+
JobCommand::init_command().await;
17+
Ok(())
1418
}
1519
}
1620
}

horizon_common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
tokio.workspace = true

horizon_common/src/api/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod state;

horizon_common/src/api/state.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::path::PathBuf;
2+
use tokio::fs::create_dir_all;
3+
4+
#[derive(Debug)]
5+
pub struct HorizonState {
6+
data_folder: PathBuf,
7+
8+
config_folder: PathBuf,
9+
}
10+
11+
impl HorizonState {
12+
pub fn new(data_folder: PathBuf, config_folder: PathBuf) -> Self {
13+
Self {
14+
data_folder,
15+
config_folder,
16+
}
17+
}
18+
19+
pub async fn init_data_folder(&self) {
20+
if !self.data_folder.exists() {
21+
create_dir_all(&self.data_folder).await.unwrap();
22+
}
23+
}
24+
25+
pub async fn init_config_folder(&self) {
26+
if !self.config_folder.exists() {
27+
create_dir_all(&self.config_folder).await.unwrap();
28+
}
29+
}
30+
}

horizon_common/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
pub mod api;
2+
13
pub fn add(left: u64, right: u64) -> u64 {
24
left + right
35
}
46

7+
pub use api::state::HorizonState as HorizonCliState;
8+
59
#[cfg(test)]
610
mod tests {
711
use super::*;

0 commit comments

Comments
 (0)