-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): created very basic cli scaffold
- Loading branch information
1 parent
a3402f2
commit 6b836ef
Showing
8 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ Cargo.lock | |
node_modules/ | ||
.perseus/ | ||
tailwind.css | ||
# This is still included in the Cargo package | ||
.tribble/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum PrepError { | ||
#[error("couldn't extract internal `.tribble/` directory, please ensure you have write permissions here")] | ||
ExtractionFailed { | ||
target_dir: Option<String>, | ||
#[source] | ||
source: std::io::Error | ||
}, | ||
#[error("couldn't update your `.gitignore`, you should add `.tribble/` to it manually")] | ||
GitignoreUpdateFailed { | ||
#[source] | ||
source: std::io::Error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
mod options; | ||
mod prep; | ||
mod errors; | ||
|
||
/// The current version of the CLI, extracted from the crate version. | ||
pub const TRIBBLE_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![allow(missing_docs)] // Prevents double-documenting some things | ||
|
||
use clap::Parser; | ||
use crate::TRIBBLE_VERSION; | ||
|
||
// The documentation for the `Opts` struct will appear in the help page, hence the lack of puncutation and the lowercasing in places | ||
|
||
/// Tribble creates seamless contribution experiences for your project. | ||
#[derive(Parser)] | ||
#[clap(version = TRIBBLE_VERSION)] | ||
pub struct Opts { | ||
#[clap(subcommand)] | ||
pub subcmd: Subcommand, | ||
} | ||
|
||
#[derive(Parser)] | ||
pub enum Subcommand { | ||
/// Builds your Tribble workflows. This is called by `tribble serve` automatically. | ||
Build, | ||
/// Serves your Tribble workflows locally for development. | ||
Serve, | ||
/// Builds your Tribble workflows for release deployment. | ||
Deploy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::path::PathBuf; | ||
|
||
use include_dir::{include_dir, Dir}; | ||
use crate::errors::*; | ||
use std::fs::{self, OpenOptions}; | ||
use std::io::Write; | ||
|
||
// We include the `.tribble/` directory because it contains pre-built Wasm artifacts | ||
static TRIBBLE_DIR: Dir = include_dir!("./.tribble"); | ||
|
||
/// Prepares the directory for running Tribble by writing the directory. Tribble has no prerequisites (not even `cargo`), so | ||
/// this doesn't need to do any prerequisite checking. | ||
pub fn prep(dir: PathBuf) -> Result<(), PrepError> { | ||
let tribble_dir = dir.join("./.tribble"); | ||
if tribble_dir.exists() { | ||
// The directory already exists, so we'll assume we don't need to do anything | ||
// This will run before every command, so we don't want to be needlessly recreating things | ||
Ok(()) | ||
} else { | ||
// Write the stored directory to that location, creating the directory first | ||
if let Err(err) = fs::create_dir(&tribble_dir) { | ||
return Err(PrepError::ExtractionFailed { | ||
target_dir: tribble_dir.to_str().map(|s| s.to_string()), | ||
source: err, | ||
}); | ||
} | ||
// Notably, this function will not do anything or tell us if the directory already exists... | ||
if let Err(err) = TRIBBLE_DIR.extract(&tribble_dir) { | ||
return Err(PrepError::ExtractionFailed { | ||
target_dir: tribble_dir.to_str().map(|s| s.to_string()), | ||
source: err, | ||
}); | ||
} | ||
|
||
// If we aren't already gitignoring the Tribble directory, update `.gitignore` to do so | ||
if let Ok(contents) = fs::read_to_string(".gitignore") { | ||
if contents.contains(".tribble/") { | ||
return Ok(()); | ||
} | ||
} | ||
let file = OpenOptions::new() | ||
.append(true) | ||
.create(true) // If it doesn't exist, create it | ||
.open(".gitignore"); | ||
let mut file = match file { | ||
Ok(file) => file, | ||
Err(err) => return Err(PrepError::GitignoreUpdateFailed { source: err }), | ||
}; | ||
// Check for errors with appending to the file | ||
if let Err(err) = file.write_all(b".tribble/") { | ||
return Err(PrepError::GitignoreUpdateFailed { source: err }); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters