-
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.
- Loading branch information
1 parent
ad9f211
commit 6578f08
Showing
7 changed files
with
118 additions
and
112 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
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,35 +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")] | ||
struct Args { | ||
#[arg(help = "source file")] | ||
#[arg(short, long, help = "source file")] | ||
source: String, | ||
#[arg(help = "output file")] | ||
#[arg(short, long, help = "output file")] | ||
output: String, | ||
} | ||
|
||
fn main() { | ||
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") => fs::write(output_path, compile(&source).expect("ehhe")) | ||
.expect("could not write output file"), | ||
Some(other) => eprintln!("file type {other} not supported"), | ||
None => eprintln!("specify an output file type"), | ||
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