Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from korosuke613/support-output
Browse files Browse the repository at this point in the history
feat: support output
  • Loading branch information
korosuke613 authored Mar 21, 2021
2 parents 236a7c6 + da28653 commit c083a9a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- run: docker tag tempura:latest ghcr.io/korosuke613/tempura:${GITHUB_REF##*/}
- run: docker push ghcr.io/korosuke613/tempura:${GITHUB_REF##*/}
- name: docker tag
run: |
docker tag tempura:latest ghcr.io/korosuke613/tempura:${GITHUB_REF##*/}
docker tag tempura:latest ghcr.io/korosuke613/tempura:latest
- name: docker push
run: |
docker push ghcr.io/korosuke613/tempura:latest
docker push ghcr.io/korosuke613/tempura:${GITHUB_REF##*/}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ dist/

input.json
template.txt
output.txt
main
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,81 @@
# tempura

## Install

Download from [Releases](https://github.com/korosuke613/tempura/releases). or `docker pull ghcr.io/korosuke613/tempura`.

## Getting Started
using binary
```
❯ tempura --input-string '{"Name": "John", "Message": "Good"}' --template-string 'Hello {{.Name}}, {{.Message}}'
Hello John, Good
```

or using docker

```
❯ docker run --rm ghcr.io/korosuke613/tempura --input-string '{"Name": "John", "Message": "Good"}' --template-string 'Hello {{.Name}}, {{.Message}}'
Hello John, Good
```


## Example

### input multiline template
```
❯ tempura \
--input-string '{"Name": "John", "Message": "Good"}' \
--template-string \
'Hello {{.Name}},
{{.Message}}'
Hello John,
Good
```

### read template and inputs

`input.json`
```json
{
"Name": "John",
"Message": "Good"
}
```

`template.txt`
```text
Hello {{.Name}},
{{.Message}}
```

```
❯ tempura -i input.json -t template.txt
Hello John,
Good
```

### output to file
```
❯ tempura -o ./output.txt
❯ cat ./output.txt
Hello John,
Good
```

### Options
```
❯ tempura -h
A Fast and Flexible Template Fill Generator built with love by korosuke613 in Go.
Usage:
tempura [flags]
Flags:
-h, --help help for tempura
-i, --input-filepath string input file name (default "input.json")
--input-string string input string
-o, --output string output file name
-t, --template-filepath string template file name (default "template.txt")
--template-string string template string
-v, --version show version
```
18 changes: 15 additions & 3 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,31 @@ func newRootCmd() *cobra.Command {
if err := t.Fill(&output); err != nil {
return err
}
fmt.Println(output)

if outputFilePath != "" {
file, err := os.Create(outputFilePath)
if err != nil {
return err
}
defer file.Close()

_, err = file.WriteString(output)
if err != nil {
return err
}
} else {
fmt.Println(output)
}
return nil
},
}
cmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "show version")
cmd.PersistentFlags().StringVarP(&inputFilePath, "input-filepath", "i", "input.json", "input file name")
cmd.PersistentFlags().StringVarP(&templateFilePath, "template-filepath", "t", "template.txt", "template file name")
cmd.PersistentFlags().StringVarP(&outputFilePath, "output", "o", "output.txt", "output file name")
cmd.PersistentFlags().StringVarP(&outputFilePath, "output", "o", "", "output file name")
cmd.PersistentFlags().StringVar(&inputString, "input-string", "", "input string")
cmd.PersistentFlags().StringVar(&templateString, "template-string", "", "template string")

cmd.SetVersionTemplate(fmt.Sprintf("version: %s, commit: %s, date: %s\n", version, commit, date))
return cmd
}

Expand Down

0 comments on commit c083a9a

Please sign in to comment.