Skip to content

Commit a93402f

Browse files
committed
Specify config file, not config directory in cli.
1 parent a4f9527 commit a93402f

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed

java-spaghetti-gen/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ impl Config {
249249
}
250250
}
251251

252+
/// Read configuration from a specific file path.
253+
pub fn from_file(path: &Path) -> io::Result<Self> {
254+
let mut file = fs::File::open(path)?;
255+
let config_dir = path.parent().unwrap_or(Path::new("."));
256+
Self::read(&mut file, config_dir)
257+
}
258+
252259
pub fn resolve_class(&self, class: &str) -> ClassConfig<'_> {
253260
let mut res = ClassConfig {
254261
include: false,

java-spaghetti-gen/src/main.rs

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ mod emit;
66
mod identifiers;
77
mod parser_util;
88

9-
fn main() {
10-
entry::main();
11-
}
12-
139
use std::error::Error;
1410
use std::fs::File;
1511
use std::io::{self, Read};
16-
use std::path::Path;
12+
use std::path::{Path, PathBuf};
13+
14+
use clap::{Parser, Subcommand};
1715

1816
use crate::config::Config;
1917
use crate::parser_util::JavaClass;
@@ -97,49 +95,48 @@ fn gather_file(context: &mut emit::Context, path: &Path) -> Result<(), Box<dyn E
9795
Ok(())
9896
}
9997

100-
mod entry {
101-
use std::path::PathBuf;
102-
103-
use clap::{Parser, Subcommand};
104-
105-
use crate::{config, run};
106-
107-
/// Autogenerate glue code for access Android JVM APIs from Rust
108-
#[derive(Parser, Debug)]
109-
#[command(version, about)]
110-
struct Cli {
111-
#[command(subcommand)]
112-
cmd: Cmd,
113-
}
114-
115-
/// Doc comment
116-
#[derive(Subcommand, Debug)]
117-
enum Cmd {
118-
Generate(GenerateCmd),
119-
}
98+
/// Autogenerate glue code for access Android JVM APIs from Rust
99+
#[derive(Parser, Debug)]
100+
#[command(version, about)]
101+
struct Cli {
102+
#[command(subcommand)]
103+
cmd: Cmd,
104+
}
120105

121-
#[derive(Parser, Debug)]
122-
struct GenerateCmd {
123-
/// Log in more detail
124-
#[arg(short, long)]
125-
verbose: bool,
106+
/// Doc comment
107+
#[derive(Subcommand, Debug)]
108+
enum Cmd {
109+
Generate(GenerateCmd),
110+
}
126111

127-
/// Sets a custom directory
128-
#[arg(short, long, default_value = ".")]
129-
directory: PathBuf,
130-
}
112+
#[derive(Parser, Debug)]
113+
struct GenerateCmd {
114+
/// Log in more detail
115+
#[arg(short, long)]
116+
verbose: bool,
131117

132-
pub fn main() {
133-
let cli = Cli::parse();
118+
/// Sets a custom config file
119+
#[arg(short, long)]
120+
config: Option<PathBuf>,
121+
}
134122

135-
match cli.cmd {
136-
Cmd::Generate(cmd) => {
137-
let mut config = config::Config::from_directory(&cmd.directory).unwrap();
138-
if cmd.verbose {
139-
config.logging_verbose = true;
140-
}
141-
run(config).unwrap();
123+
pub fn main() {
124+
let cli = Cli::parse();
125+
126+
match cli.cmd {
127+
Cmd::Generate(cmd) => {
128+
let mut config = if let Some(config_path) = cmd.config {
129+
// Use specified config file
130+
config::Config::from_file(&config_path).unwrap()
131+
} else {
132+
// Search from current working directory
133+
config::Config::from_current_directory().unwrap()
134+
};
135+
136+
if cmd.verbose {
137+
config.logging_verbose = true;
142138
}
139+
run(config).unwrap();
143140
}
144141
}
145142
}

0 commit comments

Comments
 (0)