Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(doc): generate in custom path and check if amber file exist #465

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ impl AmberCompiler {
let dir_path = {
let file_dir = dep_path.strip_prefix(&base_dir).unwrap();
let parent = file_dir.parent().unwrap().display();
format!("{}/{output}/{}", base_dir.to_string_lossy(), parent)
if !output.is_empty() {
output.clone()
} else {
format!("{}/{output}/{}", base_dir.to_string_lossy(), parent)
}
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
};
if let Err(err) = fs::create_dir_all(dir_path.clone()) {
Message::new_err_msg(format!(
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::error::Error;
use std::fs;
use std::io::{prelude::*, stdin};
use std::path::PathBuf;
use std::path::Path;
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
use std::process::Command;

#[derive(Parser, Clone, Debug)]
Expand All @@ -33,7 +34,7 @@ pub struct Cli {
eval: Option<String>,

/// Generate docs
/// (OUTPUT is dir instead, default: `docs/`)
/// (OUTPUT is dir instead, default: `docs/` if missing it will generate the folder)
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long)]
docs: bool,

Expand Down Expand Up @@ -136,6 +137,14 @@ fn handle_eval(code: String, cli: Cli) -> Result<(), Box<dyn Error>> {

fn handle_docs(cli: Cli) -> Result<(), Box<dyn Error>> {
let input = if let Some(ref input) = cli.input {
let path = Path::new(input);
if !path.exists() {
Message::new_err_msg(format!(
"Amber file doesn't exist: `{}`.", input.to_string_lossy()
))
.show();
std::process::exit(1);
}
String::from(input.to_string_lossy())
} else {
Message::new_err_msg(
Expand Down