Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _u7_complete_entities() {
COMPREPLY=($(compgen -W "ip csv json line ssl files diff cpu memory disk processes ports port usage network git env log http docker system definition functions --help" -- "$cur"))
;;
make|mk)
COMPREPLY=($(compgen -W "dir file password user copy link archive clone template sequence --help" -- "$cur"))
COMPREPLY=($(compgen -W "dir file password user copy link archive clone template sequence env --help" -- "$cur"))
;;
drop|dr)
COMPREPLY=($(compgen -W "file dir dirs files line lines column duplicates process user docker --help" -- "$cur"))
Expand Down Expand Up @@ -46,6 +46,7 @@ _u7_complete_args() {
make|mk)
case "$entity" in
copy|link) _filedir ;;
env) COMPREPLY=($(compgen -W "from" -- "$cur")) ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No file-path completion after from keyword

The current completion only suggests from as the first argument after env. Once the user types u7 mk env from <TAB>, there is no further completion, so the template file path cannot be tab-completed. Adding a _filedir fallback when no keyword matches — similar to how copy|link already does — would improve usability:

Suggested change
env) COMPREPLY=($(compgen -W "from" -- "$cur")) ;;
env) COMPREPLY=($(compgen -W "from" -- "$cur")); [[ -z "$COMPREPLY" ]] && _filedir ;;
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/completions.sh
Line: 48

Comment:
**No file-path completion after `from` keyword**

The current completion only suggests `from` as the first argument after `env`. Once the user types `u7 mk env from <TAB>`, there is no further completion, so the template file path cannot be tab-completed. Adding a `_filedir` fallback when no keyword matches — similar to how `copy|link` already does — would improve usability:

```suggestion
        env) COMPREPLY=($(compgen -W "from" -- "$cur")); [[ -z "$COMPREPLY" ]] && _filedir ;;
```

How can I resolve this? If you propose a fix, please make it concise.

template) COMPREPLY=($(compgen -W "python node bash web" -- "$cur")) ;;
esac
;;
Expand Down
31 changes: 31 additions & 0 deletions lib/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current argument parsing for mk env is not robust. It only handles a fixed order of arguments (from then to) and will ignore arguments if they don't appear in this exact sequence (e.g., u7 mk env to .env.local will be ignored). This doesn't match the flexibility suggested by the help text: env [from <template>] [to <output>].

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 stderr, which is a best practice.

      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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's a good practice to redirect error messages to standard error (stderr). This separates diagnostic messages from the script's main output, which is helpful for scripting and redirection.

Suggested change
if [[ ! -f "$template" ]]; then
echo "Error: template '$template' not found"
return 1
fi
if [[ -f "$output" ]]; then
echo "Error: '$output' already exists"
return 1
if [[ ! -f "$template" ]]; then
echo "Error: template '$template' not found" >&2
return 1
fi
if [[ -f "$output" ]]; then
echo "Error: '$output' already exists" >&2
return 1
fi

fi
_u7_exec cp "$template" "$output"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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:

Suggested change
_u7_exec cp "$template" "$output"
_u7_exec cp "$template" "$output" && echo "Created '$output' from '$template'"
Prompt To Fix With AI
This 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>"
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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:

Suggested change
env [from <template>] [to <output>] Generate .env from .env.example or a custom template
env [from <template> [to <output>]] Generate .env from .env.example or a custom template
Prompt To Fix With AI
This 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
;;
Expand Down
64 changes: 64 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make tests more robust and independent, each test should clean up all the files it creates. This test creates .env.example but only removes .env. The next test then implicitly depends on this leftover file. Please clean up .env.example here as well. You will then need to create it in the next test block.

Suggested change
rm -f .env
rm -f .env .env.example


# Test: mk env errors when .env already exists
echo "existing" > .env

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make this test self-contained, it should create its own prerequisite files. Since the previous test should now be cleaning up .env.example, you need to create it here.

Suggested change
echo "existing" > .env
echo "DB_HOST=localhost" > .env.example
echo "existing" > .env

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
Expand Down
Loading