Skip to content

Commit

Permalink
Merge pull request #5 from heronimus/v0.1.2
Browse files Browse the repository at this point in the history
V0.1.2
  • Loading branch information
heronimus authored Nov 27, 2021
2 parents 207e6e2 + c3ccb8f commit a8ec926
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

build/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Consul-Template Plugin: string2files
Lightweight Consul-Template plugin that (basically) write string to file(s). Created because I need easy way to write multiple files from Consul KV tree with only single template :v:.

Build with V language compiler: `V 0.2.4 8315e82`.

### Credits
This plugin heavily inspired by:
- [tam7t/certdump.go Gist](https://gist.github.com/tam7t/1b45125ae4de13b3fc6fd0455954c08e)
Expand Down Expand Up @@ -237,7 +239,8 @@ This plugin written in V, so you must have V compiler installed.
```
- Binary will created at working directory (`string2files` / `string2files.exe` for Windows)
> *Notes: V allows you to cross compilation by passing flag `-os <windows/linux>`, macOS binary only can be compiled on macOS platform.
> *Notes: V allows you to cross compilation by passing flag `-os <windows/linux>`, m acOS binary only can be compiled on macOS platform.
> *Build with V compiler version: V 0.2.4 8315e82
### More About V
Please visit official website and docs:
Expand Down
12 changes: 9 additions & 3 deletions filewriter/filewriter_util.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ import os

fn (mut fw FileWriter) write_ofile() {
if fw.is_newline {
fw.ofile.writeln(fw.content)
fw.ofile.writeln(fw.content) or {
fw.logger.fatal("error while write content to '$fw.path'.")
}
return
}
fw.ofile.write_string(fw.content)
fw.ofile.write_string(fw.content) or {
fw.logger.fatal("error while write content to '$fw.path'.")
}
}

fn (mut fw FileWriter) create_dir() {
dir := os.dir(fw.path)
if !os.is_dir(dir) {
fw.logger.info("directory not exist, creating '$dir'.")
os.mkdir_all(dir)
os.mkdir_all(dir) or {
fw.logger.fatal("error while create dir: '$dir'.")
}
if !os.is_dir(dir) {
fw.logger.fatal("directory not created: '$dir'.")
}
Expand Down
12 changes: 6 additions & 6 deletions string2files.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
mut cmd := Command{
name: 'string2files'
description: 'Consul-Template plugin that (basically) write string to file(s).'
version: '0.1.1'
version: '0.1.2'
}
// CLI Command
mut append_cmd := Command{
Expand Down Expand Up @@ -38,14 +38,14 @@ fn main() {
flag: .bool
name: 'force'
abbrev: 'f'
value: 'false'
value: ['false']
description: 'Create new directory/file from <path-file> if not exist.'
}
cli_flags << Flag{
flag: .bool
name: 'new-line'
abbrev: 'nl'
value: 'false'
value: ['false']
description: 'Add new line in the end of file.'
}
append_cmd.add_flags(cli_flags)
Expand All @@ -58,7 +58,7 @@ fn main() {
cmd.parse(os.args)
}

fn append_func(cmd Command) {
fn append_func(cmd Command) ? {
flag_force := cmd.flags.get_bool('force') or {
panic('Failed to get `force` flag: $err')
}
Expand All @@ -76,7 +76,7 @@ fn append_func(cmd Command) {
fw.append_file()
}

fn create_func(cmd Command) {
fn create_func(cmd Command) ? {
flag_force := cmd.flags.get_bool('force') or {
panic('Failed to get `force` flag: $err')
}
Expand All @@ -94,7 +94,7 @@ fn create_func(cmd Command) {
fw.create_file()
}

fn explode_func(cmd Command) {
fn explode_func(cmd Command) ? {
mut flags := map[string]bool{}
flags['force'] = cmd.flags.get_bool('force') or {
panic('Failed to get `force` flag: $err')
Expand Down

0 comments on commit a8ec926

Please sign in to comment.