46 lines
1.3 KiB
Makefile
46 lines
1.3 KiB
Makefile
.PHONY: build run clean test help
|
|
|
|
OUT_DIR=dist
|
|
BINARY_NAME=argparse-builder.bin
|
|
PORT=8080
|
|
|
|
help:
|
|
@echo "Available targets:"
|
|
@echo " build - Build the binary"
|
|
@echo " run - Run the server"
|
|
@echo " clean - Remove built artifacts"
|
|
@echo " test - Test the API endpoint"
|
|
@echo " strip - Build optimized binary (smaller size)"
|
|
|
|
build:
|
|
@echo "Building $(BINARY_NAME)..."
|
|
go build -o $(OUT_DIR)/$(BINARY_NAME)
|
|
@echo "Built: $(BINARY_NAME) ($$(du -h $(OUT_DIR)/$(BINARY_NAME) | cut -f1))"
|
|
|
|
strip:
|
|
@echo "Building optimized $(BINARY_NAME)..."
|
|
go build -ldflags="-s -w" -o $(OUT_DIR)/$(BINARY_NAME)
|
|
@echo "Built: $(BINARY_NAME) ($$(du -h $(OUT_DIR)/$(BINARY_NAME) | cut -f1))"
|
|
|
|
run: build
|
|
@echo "Starting server on :$(PORT)..."
|
|
./$(OUT_DIR)/$(BINARY_NAME)
|
|
|
|
clean:
|
|
@echo "Cleaning..."
|
|
rm -f $(OUT_DIR)/$(BINARY_NAME)
|
|
@echo "Done"
|
|
|
|
test: build
|
|
@echo "Testing API endpoint..."
|
|
@./$(OUT_DIR)/$(BINARY_NAME) & \
|
|
SERVER_PID=$$!; \
|
|
sleep 2; \
|
|
curl -s -X POST http://localhost:$(PORT)/generate \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"header":"Test Script","arguments":[{"params":"-v --verbose","command":"verbose","helpText":"Verbose"}]}' \
|
|
> /tmp/test_output.sh; \
|
|
kill $$SERVER_PID 2>/dev/null; \
|
|
echo "Generated test script:"; \
|
|
cat /tmp/test_output.sh
|