Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target/
target/
out/
playdate-docs
3 changes: 2 additions & 1 deletion .zed/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"wrap_guides": [100]
"wrap_guides": [100],
"file_scan_inclusions": [".env*", "playdate-docs/**"],
}
10 changes: 10 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ pub struct Args {
/// Verbose logging (-v, -vv, -vvv, etc.)
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,

/// Compact function stubs (---@type + local name)
#[arg(long)]
pub compact: bool,

/// Compact output to stdout (non-segmented)
#[arg(long)]
pub llm: bool,
}

// CLI Action: Generate Function Stubs or full Lua with annotation comments
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Action {
Stub,
Annotate,
Multi,
Md,
}

fn get_sdk_dir() -> PathBuf {
Expand Down
42 changes: 38 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,67 @@

mod args;
mod luars;
mod md;
mod multi;
mod output;
mod scraper;

use args::Action;
use md::write_markdown_docs;
use multi::MultiStubOutput;
use output::StubOutput;
use std::fs;
use std::path::Path;

static PLAYDATE_LUARS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/playdate.luars"));

fn main() {
let args = args::parse();

// Parse the .luars type definitions
let statements =
luars::parse_document(PLAYDATE_LUARS).expect("Failed to parse playdate.luars");
let statements = luars::parse_document(PLAYDATE_LUARS).expect("Failed to parse playdate.luars");

if args.llm {
let output = StubOutput::from_statements(&statements, true, true);
output.print();
return;
}

match args.action {
Action::Stub => {
// Generate stubs without documentation
let output = StubOutput::from_statements(&statements);
let output = StubOutput::from_statements(&statements, args.compact, false);
output.print();
}
Action::Annotate => {
// Scrape documentation and generate annotated stubs
let html = args::fetch_docs(&args);
let scraped = scraper::scrape(&html, &statements);
let output = StubOutput::from_statements_with_docs(&statements, &scraped);
let output =
StubOutput::from_statements_with_docs(&statements, &scraped, args.compact, false);
output.print();
}
Action::Md => {
let html = args::fetch_docs(&args);
let scraped = scraper::scrape(&html, &statements);
let out_dir = Path::new("playdate-docs");
if out_dir.exists() {
fs::remove_dir_all(out_dir).expect("Failed to clear playdate-docs/ directory");
}
fs::create_dir_all(out_dir).expect("Failed to create playdate-docs/ directory");
write_markdown_docs(&scraped, &statements, out_dir)
.expect("Failed to write markdown docs");
}
Action::Multi => {
let output = MultiStubOutput::from_statements(&statements, args.compact);
let out_dir = Path::new("out");
if out_dir.exists() {
fs::remove_dir_all(out_dir).expect("Failed to clear out/ directory");
}
fs::create_dir_all(out_dir).expect("Failed to create out/ directory");
output
.write_to_dir(out_dir)
.expect("Failed to write multi-file output");
}
}
}
Loading