-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add mk env for generating .env files #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -170,6 +170,36 @@ _u7_make() { | |||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| env) | ||||||||||||||||||||||||||||||||
| local template=".env.example" | ||||||||||||||||||||||||||||||||
| local output=".env" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if [[ "$1" == "from" ]]; then | ||||||||||||||||||||||||||||||||
| if [[ -z "$2" ]]; then | ||||||||||||||||||||||||||||||||
| echo "Usage: u7 mk env from <template> [to <output>]" | ||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| template="$2" | ||||||||||||||||||||||||||||||||
| if [[ "$3" == "to" ]]; then | ||||||||||||||||||||||||||||||||
| if [[ -z "$4" ]]; then | ||||||||||||||||||||||||||||||||
| echo "Usage: u7 mk env from <template> to <output>" | ||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| output="$4" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
Comment on lines
+177
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current argument parsing for To handle keyword arguments correctly, it's better to process them in a loop. This makes the command more user-friendly and less prone to errors. I've also updated the error messages to print to while [[ $# -gt 0 ]]; do
case "$1" in
from)
if [[ -z "$2" ]]; then
echo "Usage: u7 mk env from <template> [to <output>]" >&2
return 1
fi
template="$2"
shift 2
;;
to)
if [[ -z "$2" ]]; then
echo "Usage: u7 mk env [from <template>] to <output>" >&2
return 1
fi
output="$2"
shift 2
;;
*)
echo "Error: Unknown argument '$1' for 'mk env'" >&2
echo "Usage: u7 mk env [from <template>] [to <output>]" >&2
return 1
;;
esac
done |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if [[ ! -f "$template" ]]; then | ||||||||||||||||||||||||||||||||
| echo "Error: template '$template' not found" | ||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| if [[ -f "$output" ]]; then | ||||||||||||||||||||||||||||||||
| echo "Error: '$output' already exists" | ||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||
|
Comment on lines
+192
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good practice to redirect error messages to standard error (
Suggested change
|
||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| _u7_exec cp "$template" "$output" | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: lib/make.sh
Line: 200
Comment:
**No success feedback message**
The `cp` command produces no output on success, leaving the user with no confirmation that `.env` was created. Other similar entities (e.g., `copy`, `template`) print a success line. Adding one here would keep the UX consistent:
```suggestion
_u7_exec cp "$template" "$output" && echo "Created '$output' from '$template'"
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| sequence) | ||||||||||||||||||||||||||||||||
| if [[ "$1" != "with" || "$2" != "prefix" ]]; then | ||||||||||||||||||||||||||||||||
| echo "Usage: u7 mk sequence with prefix <prefix> limit <N>" | ||||||||||||||||||||||||||||||||
|
|
@@ -202,6 +232,7 @@ Entities: | |||||||||||||||||||||||||||||||
| archive <output> from <files...> Create archive from <files...> to <output> | ||||||||||||||||||||||||||||||||
| clone <repo> [to <directory>] Git clone a repository | ||||||||||||||||||||||||||||||||
| template <python|node|bash|web> <name> Scaffold a project structure | ||||||||||||||||||||||||||||||||
| env [from <template>] [to <output>] Generate .env from .env.example or a custom template | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current help text implies However, in the implementation
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: lib/make.sh
Line: 235
Comment:
**Misleading syntax in help text**
The current help text implies `[to <output>]` can be used independently of `[from <template>]`:
```
env [from <template>] [to <output>]
```
However, in the implementation `to <output>` is only parsed when `from <template>` is already present — calling `u7 mk env to custom.env` silently ignores `to custom.env` and falls back to the default `.env` output. The help text should reflect the actual nested-optional structure:
```suggestion
env [from <template> [to <output>]] Generate .env from .env.example or a custom template
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||
| sequence with prefix <prefix> limit <N> Generate numbered sequence with prefix <prefix> and limit <N> | ||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1022,6 +1022,70 @@ else | |||||
| ((PASSED++)) | ||||||
| fi | ||||||
|
|
||||||
| # ===== mk env tests ===== | ||||||
|
|
||||||
| # Test: mk env copies .env.example to .env | ||||||
| echo "DB_HOST=localhost" > .env.example | ||||||
| echo "# comment line" >> .env.example | ||||||
| echo "DB_PORT=5432" >> .env.example | ||||||
| result=$(u7 mk env 2>&1) | ||||||
| if [[ -f .env ]]; then | ||||||
| content=$(cat .env) | ||||||
| expected=$(cat .env.example) | ||||||
| assert_equals "mk env copies .env.example to .env" "$expected" "$content" | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk env copies .env.example to .env (file not created)" | ||||||
| ((FAILED++)) | ||||||
| fi | ||||||
| rm -f .env | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make tests more robust and independent, each test should clean up all the files it creates. This test creates
Suggested change
|
||||||
|
|
||||||
| # Test: mk env errors when .env already exists | ||||||
| echo "existing" > .env | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| result=$(u7 mk env 2>&1) | ||||||
| assert_contains "mk env errors when .env exists" "already exists" "$result" | ||||||
| rm -f .env .env.example | ||||||
|
|
||||||
| # Test: mk env errors when .env.example is missing | ||||||
| result=$(u7 mk env 2>&1) | ||||||
| assert_contains "mk env errors when template missing" "not found" "$result" | ||||||
|
|
||||||
| # Test: mk env from <template> | ||||||
| echo "KEY=value" > custom.template | ||||||
| result=$(u7 mk env from custom.template 2>&1) | ||||||
| if [[ -f .env ]]; then | ||||||
| content=$(cat .env) | ||||||
| assert_equals "mk env from custom template" "KEY=value" "$content" | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk env from custom template (file not created)" | ||||||
| ((FAILED++)) | ||||||
| fi | ||||||
| rm -f .env custom.template | ||||||
|
|
||||||
| # Test: mk env from <template> to <output> | ||||||
| echo "SECRET=abc" > my.template | ||||||
| result=$(u7 mk env from my.template to config.env 2>&1) | ||||||
| if [[ -f config.env ]]; then | ||||||
| content=$(cat config.env) | ||||||
| assert_equals "mk env from template to output" "SECRET=abc" "$content" | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk env from template to output (file not created)" | ||||||
| ((FAILED++)) | ||||||
| fi | ||||||
| rm -f config.env my.template | ||||||
|
|
||||||
| # Test: mk env dry-run does not create file | ||||||
| echo "DRY=run" > .env.example | ||||||
| result=$(u7 -n mk env 2>&1) | ||||||
| assert_contains "mk env dry-run prints command" "cp" "$result" | ||||||
| if [[ ! -f .env ]]; then | ||||||
| echo -e "${GREEN}✓${NC} mk env dry-run does not create file" | ||||||
| ((PASSED++)) | ||||||
| else | ||||||
| echo -e "${RED}✗${NC} mk env dry-run does not create file" | ||||||
| ((FAILED++)) | ||||||
| fi | ||||||
| rm -f .env.example | ||||||
|
|
||||||
| # ===== cv json to csv tests ===== | ||||||
|
|
||||||
| # Test: Convert JSON to CSV | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromkeywordThe current completion only suggests
fromas the first argument afterenv. Once the user typesu7 mk env from <TAB>, there is no further completion, so the template file path cannot be tab-completed. Adding a_filedirfallback when no keyword matches — similar to howcopy|linkalready does — would improve usability:Prompt To Fix With AI