-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* creating file output + refactoring * very simple clap implementation
- Loading branch information
1 parent
9d3cc68
commit 5670c15
Showing
8 changed files
with
126 additions
and
119 deletions.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
/result |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
{ | ||
description = "A very basic flake"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs"; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
nixpkgs, | ||
}: let | ||
system = "x86_64-linux"; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
in { | ||
devShells.${system}.default = pkgs.mkShell { | ||
buildInputs = [ | ||
pkgs.vim | ||
pkgs.cargo | ||
pkgs.clippy | ||
pkgs.rustfmt | ||
pkgs.f3d | ||
pkgs.git | ||
]; | ||
}; | ||
packages.x86_64-linux.default = pkgs.rustPlatform.buildRustPackage rec { | ||
name = "kodama"; | ||
src = ./.; | ||
|
||
cargoHash = "sha256-U9Un9x9EfIrJ2Zmem935SIes3KF2Aq8eip5u4PkBWFI="; | ||
}; | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,39 +1,23 @@ | ||
use clap::Parser; | ||
use kodama::compiler::compile; | ||
use std::ffi::OsStr; | ||
use kodama::compiler::*; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
#[derive(Parser)] | ||
#[command( | ||
author = "David Lynch", | ||
about = "3d modelling but epic", | ||
long_about = "lengthy epic" | ||
)] | ||
#[command(author = "David Lynch", about = "3d modelling but epic")] | ||
struct Args { | ||
#[arg(help = "source file")] | ||
#[arg(short, long, help = "source file")] | ||
source: String, | ||
#[arg(help = "output file", default_value = "")] | ||
#[arg(short, long, help = "output file")] | ||
output: String, | ||
} | ||
|
||
fn main() { | ||
println!("{}", compile("sphere 1")); | ||
|
||
let args = Args::parse(); | ||
|
||
let source_path = Path::new(&args.source); | ||
let output_path = Path::new(&args.output); | ||
|
||
if source_path.extension().and_then(OsStr::to_str) != Some("kda") { | ||
eprintln!("please specify a kodama source file"); | ||
return; | ||
} | ||
let source = fs::read_to_string(source_path).expect("couldn't load source file"); | ||
|
||
match output_path.extension().and_then(OsStr::to_str) { | ||
Some("obj") => println!("{}", compile(&source)), | ||
Some(other) => eprintln!("file type {other} not supported"), | ||
None => println!("{}", compile(&source)), | ||
let contents = fs::read_to_string(args.source).expect("File not found"); | ||
if let Ok(result) = compile(&contents) { | ||
if let Err(e) = fs::write(args.output, result) { | ||
panic!("{}", e) | ||
} | ||
} | ||
} |
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