0.2.1: bug fix overwrite mode

This commit is contained in:
Adam 2025-08-17 01:00:16 +01:00
parent e4780cf729
commit 5c098cfc98
5 changed files with 10 additions and 6 deletions

2
Cargo.lock generated
View File

@ -4,7 +4,7 @@ version = 4
[[package]]
name = "bin2hpp"
version = "0.2.0"
version = "0.2.1"
dependencies = [
"thiserror",
]

View File

@ -1,6 +1,6 @@
[package]
name = "bin2hpp"
version = "0.2.0"
version = "0.2.1"
authors = ["Adam Macdonald"]
edition = "2024"
license = "GPL-3.0-only"

View File

@ -69,7 +69,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result<Config, ProgramConfigErr
constness: args.constness,
symbol_name: match &args.symbol_name {
Some(s) => {
if s.chars().all(|c| c.is_ascii_alphanumeric()) {
if s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
s.to_string()
} else {
return Err(ProgramConfigError::InvalidSymbolName(s.to_string()));
@ -101,7 +101,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result<Config, ProgramConfigErr
},
namespace: match &args.namespace {
Some(ns) => {
if ns.chars().all(|c| c.is_ascii_alphanumeric()) {
if ns.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
Some(ns.to_string())
} else {
return Err(ProgramConfigError::InvalidSymbolName(ns.to_string()));
@ -111,7 +111,7 @@ pub fn parse_config_from_args(args: &CliArgs) -> Result<Config, ProgramConfigErr
},
guard_name: match &args.guard_name {
Some(guard) => {
if guard.chars().all(|c| c.is_ascii_alphanumeric()) {
if guard.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
guard.clone()
} else {
return Err(ProgramConfigError::InvalidSymbolName(guard.to_string()));

View File

@ -21,9 +21,11 @@ OUTPUT OPTIONS:
--lf Use UNIX-style LF line endings (default)
--crlf Use Windows-style CRLF line endings
--mutable Whether the symbol should not be marked as const
--const Whether the symbol should be marked as const (default)
--constexpr Whether the symbol should be marked as constexpr (C++ mode)
--symname NAME Symbol name
--namespace NAME Namespace in which the symbol will exist
(uses namespace example {} in C++ mode and prepends
@ -46,5 +48,7 @@ BYTES TYPES FOR ARRAYS:
--u8 C/C++'s (std::)uint8_t type
--i8 C/C++'s (std::)int8_t type
MISCELLANEOUS:
-h | --help Show this help text
-v | --version Print the program's build & version information";

View File

@ -87,7 +87,7 @@ fn write_header(config: &Config) -> Result<(), HeaderGenerationError> {
let out_file = OpenOptions::new()
.write(true)
.truncate(config.overwrite)
.create_new(!config.overwrite)
.create(true)
.open(config.output_file_path.clone())
.expect("failed to open input file");
let mut writer = BufWriter::new(out_file);