Skip to content

Commit

Permalink
Cli: better interactive mode check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest1338 committed Feb 1, 2025
1 parent 16980af commit c1a4a70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct AppArgs {
pub output: PathBuf,
}

pub fn get_args(args: Vec<String>) -> AppArgs {
pub fn get_args(args: &Vec<String>) -> AppArgs {
let mut args = args.iter().skip(1); // Skip the program name

let mut input = None;
Expand Down
8 changes: 3 additions & 5 deletions src/black.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use std::{
};

// TODO:
// - more test cases for error returns (eg var access when doesnt exist in interpreter)
// - restructurize so the copiler and interpreter are libraries and cli is a bin
// - if, else expr
// - fn expr
// - type checker
Expand All @@ -20,7 +18,6 @@ use std::{
// - formatter (another bin)
// - build system (toml? github repos as packages. line eg. Ernest1338/package = "0.1")
// - more test cases
// - build for arm64 in actions, upload artifacts

mod args;
use args::get_args;
Expand Down Expand Up @@ -48,9 +45,10 @@ const INTERACTIVE_BANNER: &str = "\

/// Entry point of the language CLI
fn main() {
let args = get_args(std::env::args().collect());
let env_args = std::env::args().collect();
let args = get_args(&env_args);

if args.input.is_none() {
if env_args.len() == 1 {
// ----------------
// Interactive mode
// ----------------
Expand Down
8 changes: 4 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ fn cli_interpreter() {

#[test]
fn args_interpreter() {
let app_args = get_args(args(&["binary", "-i", "input"]));
let app_args = get_args(&args(&["binary", "-i", "input"]));
assert!(
app_args
== AppArgs {
Expand All @@ -402,7 +402,7 @@ fn args_interpreter() {

#[test]
fn args_compiler_out() {
let app_args = get_args(args(&["binary", "-o", "outfile"]));
let app_args = get_args(&args(&["binary", "-o", "outfile"]));
assert!(
app_args
== AppArgs {
Expand All @@ -417,7 +417,7 @@ fn args_compiler_out() {

#[test]
fn args_build_and_run_out() {
let app_args = get_args(args(&["binary", "-r", "-o", "outfile"]));
let app_args = get_args(&args(&["binary", "-r", "-o", "outfile"]));
assert!(
app_args
== AppArgs {
Expand All @@ -428,7 +428,7 @@ fn args_build_and_run_out() {
output: PathBuf::from("outfile")
}
);
let app_args = get_args(args(&["binary", "-o", "outfile", "-r"]));
let app_args = get_args(&args(&["binary", "-o", "outfile", "-r"]));
assert!(
app_args
== AppArgs {
Expand Down

0 comments on commit c1a4a70

Please sign in to comment.