Compare commits
	
		
			12 Commits
		
	
	
		
			c072fea9a8
			...
			581165ca4c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 581165ca4c | |||
| f40e91ea42 | |||
| a076b6347a | |||
| f7b7ce075a | |||
| a90e996b7d | |||
| 308fe5666b | |||
| 25272afe15 | |||
| 5a04c52876 | |||
| fd2c37aae2 | |||
| 1a2ded6f2a | |||
| 682166307b | |||
| 7b5f7a70c1 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -22,6 +22,7 @@ go.work | |||||||
| 
 | 
 | ||||||
| # By Reza | # By Reza | ||||||
| build/ | build/ | ||||||
|  | dist/ | ||||||
| .archive/ | .archive/ | ||||||
| .vagrant/ | .vagrant/ | ||||||
| .env | .env | ||||||
|  | |||||||
| @ -5,31 +5,24 @@ builds: | |||||||
|       - CGO_ENABLED=0 |       - CGO_ENABLED=0 | ||||||
|     goos: |     goos: | ||||||
|       - linux |       - linux | ||||||
|       - darwin |  | ||||||
|       - windows |  | ||||||
|     goarch: |     goarch: | ||||||
|       - amd64 |       - amd64 | ||||||
|       - arm64 |       - arm64 | ||||||
|  |       - arm | ||||||
|  |     goarm: | ||||||
|  |       - 7 # For ARMv7 | ||||||
| 
 | 
 | ||||||
| gitea_urls: | gitea_urls: | ||||||
|   api: https://git.behzadan.ir/api/v1/ |   api: https://git.behzadan.ir/api/v1/ | ||||||
| 
 | 
 | ||||||
| # If you want to push the release to GitHub, configure the GitHub section. | # Need a Gitea token with repo access stored in your environment as GITEA_TOKEN. | ||||||
| # You'll need a GitHub token with repo access stored in your environment as GITHUB_TOKEN. |  | ||||||
| release: | release: | ||||||
|   # github: |  | ||||||
|   #   owner: yourgithubusername |  | ||||||
|   #   name: yourrepositoryname |  | ||||||
|   gitea: |   gitea: | ||||||
|     owner: p |     owner: reza | ||||||
|     name: minitmpl |     name: minitmpl | ||||||
| 
 | 
 | ||||||
| # If you want to create archives (tar.gz for Linux/Darwin, zip for Windows) |  | ||||||
| archives: | archives: | ||||||
|   - format: tar.gz |   - format: tar.gz | ||||||
|     format_overrides: |  | ||||||
|       - goos: windows |  | ||||||
|         format: zip |  | ||||||
|     files: |     files: | ||||||
|       - LICENSE |       - LICENSE | ||||||
|       - README.md |       - README.md | ||||||
|  | |||||||
							
								
								
									
										52
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | |||||||
|  | PROJECT_NAME := minitmpl | ||||||
|  | VERSION := $(shell cat VERSION) | ||||||
|  | BUILD_DIR := build | ||||||
|  | DIST_DIR := dist | ||||||
|  | LDFLAGS := "-w -s" | ||||||
|  | VVERSION := v$(VERSION) | ||||||
|  | 
 | ||||||
|  | build: | ||||||
|  | 	@echo "Building for this platform ..." | ||||||
|  | 	@mkdir -p $(BUILD_DIR) | ||||||
|  | 	@CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME) main.go | ||||||
|  | 	@echo "Build complete!" | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | .PHONY: release | ||||||
|  | release: | ||||||
|  | 	@echo "Check if the git working directory is clean" | ||||||
|  | 	@if [ -n "$$(git status --porcelain)" ]; then \
 | ||||||
|  | 		echo "Error: The working directory is not clean. Please commit or stash your changes."; \
 | ||||||
|  | 		exit 1; \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	@echo "Check if the version tag already exists and does not point to HEAD" | ||||||
|  | 	@if git rev-parse $(VVERSION) >/dev/null 2>&1; then \
 | ||||||
|  | 		if ! git describe --tags --exact-match HEAD >/dev/null 2>&1; then \
 | ||||||
|  | 			echo "Error: Version $(VVERSION) is already tagged on a different commit."; \
 | ||||||
|  | 			exit 1; \
 | ||||||
|  | 		fi; \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	@echo "Tag the latest commit with the version from VERSION file if not already tagged" | ||||||
|  | 	@if ! git describe --tags --exact-match HEAD >/dev/null 2>&1; then \
 | ||||||
|  | 		echo "Latest commit not tagged. Tagging with version from VERSION file..."; \
 | ||||||
|  | 		git tag -a $(VVERSION) -m "Release $(VVERSION)"; \
 | ||||||
|  | 		git push origin $(VVERSION); \
 | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	@echo "Set GITEA_TOKEN variable and run goreleaser" | ||||||
|  | 	@$(eval GITEA_TOKEN=$(shell pass www/behzadan.ir/git/reza/tokens/dt06-goreleaser)) | ||||||
|  | 	@goreleaser release | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | .PHONY: run | ||||||
|  | run: | ||||||
|  | 	go run main.go $(filter-out $@,$(MAKECMDGOALS)) | ||||||
|  | %: | ||||||
|  | 	@: | ||||||
|  | 
 | ||||||
|  | clean: | ||||||
|  | 	@echo "Cleaning up..." | ||||||
|  | 	@rm -rf ${BUILD_DIR} | ||||||
|  | 	@rm -rf ${DIST_DIR} | ||||||
							
								
								
									
										48
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								README.md
									
									
									
									
									
								
							| @ -0,0 +1,48 @@ | |||||||
|  | # MiniTMPL | ||||||
|  | 
 | ||||||
|  | MiniTMPL is a simple, yet powerful tool designed to render text templates using environment variables. It reads a template from `stdin` and outputs the rendered version to `stdout`, making it an excellent tool for generating configuration files, messages, or any text-based content that requires dynamic data insertion. | ||||||
|  | 
 | ||||||
|  | ## Features | ||||||
|  | 
 | ||||||
|  | - Reads templates from standard input (`stdin`). | ||||||
|  | - Renders templates using environment variables. | ||||||
|  | - Supports basic template functions provided by Go's `text/template` package. | ||||||
|  | 
 | ||||||
|  | ## Getting Started | ||||||
|  | 
 | ||||||
|  | To use EnvTemplater, clone this repository or download the latest release to your local machine. | ||||||
|  | 
 | ||||||
|  | ### Prerequisites | ||||||
|  | 
 | ||||||
|  | Ensure you have Go installed on your system. EnvTemplater requires Go 1.14 or higher. | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ### Building form source | ||||||
|  | 
 | ||||||
|  | First, clone the repository: | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | git clone https://git.behzadan.ir/p/minitmpl.git | ||||||
|  | cd minitmpl | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Then, build the program: | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | go build -o minitmpl | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## Usage | ||||||
|  | 
 | ||||||
|  | To use EnvTemplater, simply pipe a template into the program and it will output the rendered version: | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | echo "Hello, {{.USER}}" | ./envtemplater | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | This will replace `{{.USER}}` with the value of the `USER` environment variable. | ||||||
|  | 
 | ||||||
|  | ## License | ||||||
|  | 
 | ||||||
|  | This project is licensed under its own License - see the [LICENSE](LICENSE) file for details. | ||||||
|  | 
 | ||||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -1,3 +1,3 @@ | |||||||
| module git.behzadan.ir/p/minitmpl | module git.behzadan.ir/reza/minitmpl | ||||||
| 
 | 
 | ||||||
| go 1.22.0 | go 1.22.0 | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.go
									
									
									
									
									
								
							| @ -2,6 +2,7 @@ package main | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bufio" | 	"bufio" | ||||||
|  | 	"embed" | ||||||
| 	"flag" | 	"flag" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
| @ -9,7 +10,8 @@ import ( | |||||||
| 	"text/template" | 	"text/template" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const version = "1.0.1" | //go:embed VERSION
 | ||||||
|  | var versionFile embed.FS | ||||||
| 
 | 
 | ||||||
| func printHelp() { | func printHelp() { | ||||||
| 	helpText := fmt.Sprintf(` | 	helpText := fmt.Sprintf(` | ||||||
| @ -35,7 +37,12 @@ func main() { | |||||||
| 
 | 
 | ||||||
| 	// Handle version flag
 | 	// Handle version flag
 | ||||||
| 	if *versionFlag { | 	if *versionFlag { | ||||||
| 		fmt.Println("Version:", version) | 		version, err := versionFile.ReadFile("VERSION") | ||||||
|  | 		if err != nil { | ||||||
|  | 			fmt.Fprintf(os.Stderr, "Error reading version: %v\n", err) | ||||||
|  | 			os.Exit(1) | ||||||
|  | 		} | ||||||
|  | 		fmt.Println("Version:", strings.TrimSpace(string(version))) | ||||||
| 		os.Exit(0) | 		os.Exit(0) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user