-
Notifications
You must be signed in to change notification settings - Fork 2
add sample script #95
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
Conversation
Reviewer's GuideAdds a standalone Python helper script that interactively writes a preconfigured Justfile for an Axum/Docker/SeaORM project into a user-specified directory, with basic validation and error handling. Sequence diagram for the new Justfile creation scriptsequenceDiagram
actor User
participant Script as create_axum_justfile_py
participant OS
participant FileSystem
User->>Script: Run script
Script->>User: Prompt for target directory
User-->>Script: Enter target_dir
Script->>OS: Validate target_dir is nonempty
alt directory_not_provided
Script->>User: Print error for missing directory
Script->>OS: Exit with status 1
else directory_provided
Script->>OS: Check if target_dir is directory
alt not_a_directory
Script->>User: Print invalid directory error
Script->>OS: Exit with status 1
else is_directory
Script->>FileSystem: Check if Justfile exists in target_dir
alt justfile_exists
Script->>User: Print Justfile already exists error
Script->>OS: Exit with status 1
else justfile_missing
Script->>FileSystem: Create and write Justfile with template
alt write_failed
Script->>User: Print write failure message
Script->>OS: Exit with status 1
else write_succeeded
Script->>User: Print success message with path
Script->>OS: Exit with status 0
end
end
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - I've found 2 issues, and left some high level feedback:
- Consider allowing the target directory to be passed as a command-line argument (with a fallback to interactive input) so the script can be used more easily in non-interactive or scripted environments.
- The Justfile content includes hard-coded values like the docker-compose file name and the MySQL connection URL; extracting these into clearly marked placeholders or script arguments would make the generated file safer and more reusable across projects.
- There is a minor inconsistency in the Justfile aliases (e.g.,
alias config:= configurevs others with spaces around:=); normalizing this improves readability and reduces the chance of subtle parsing issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider allowing the target directory to be passed as a command-line argument (with a fallback to interactive input) so the script can be used more easily in non-interactive or scripted environments.
- The Justfile content includes hard-coded values like the docker-compose file name and the MySQL connection URL; extracting these into clearly marked placeholders or script arguments would make the generated file safer and more reusable across projects.
- There is a minor inconsistency in the Justfile aliases (e.g., `alias config:= configure` vs others with spaces around `:=`); normalizing this improves readability and reduces the chance of subtle parsing issues.
## Individual Comments
### Comment 1
<location> `scripts/create-axum-justfile.py:88` </location>
<code_context>
+ @sea-orm-cli migrate generate "{{target}}"
+
+@generate-entities:
+ sea-orm-cli generate entity --database-url=mysql://community:community@localhost:3307/community --with-serde both -o src/entities
+"""
+
</code_context>
<issue_to_address>
**🚨 issue (security):** Hard-coded DB credentials and connection string should be externalized
`--database-url=mysql://community:community@localhost:3307/community` embeds credentials and connection details directly in the Justfile, which is risky even for local use if the file is shared or checked in. Use an environment variable or `.env` value (e.g. `DATABASE_URL`) and reference it in the Justfile (e.g. `--database-url=${DATABASE_URL}`) instead of hard-coding secrets and host/port details.
</issue_to_address>
### Comment 2
<location> `scripts/create-axum-justfile.py:92-94` </location>
<code_context>
+"""
+
+def main():
+ target_dir = input("Enter directory to create Justfile in: ").strip()
+
+ if not target_dir:
+ print("Error: No directory provided")
+ sys.exit(1)
</code_context>
<issue_to_address>
**suggestion:** Using interactive input only may limit automation and scriptability
Because this is under `scripts/`, it may be used in automated flows (e.g. project bootstrap). Requiring interactive `input()` only makes that difficult. Please also accept the target directory as a CLI argument (e.g. via `sys.argv`/`argparse`), and only prompt with `input()` when no argument is given, so it remains usable both interactively and in automation.
Suggested implementation:
```python
def main():
# Prefer CLI argument for automation; fall back to interactive prompt
if len(sys.argv) > 1:
target_dir = sys.argv[1].strip()
else:
target_dir = input("Enter directory to create Justfile in: ").strip()
if not target_dir:
print("Error: No directory provided")
sys.exit(1)
```
1. Ensure `import sys` is present at the top of `scripts/create-axum-justfile.py` (and `import os` if not already imported), since `sys.argv` and `os.path` are used.
2. If this script is intended to be run as a module, confirm there is a `if __name__ == "__main__": main()` block so the new CLI behavior is used when executed directly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @sea-orm-cli migrate generate "{{target}}" | ||
|
|
||
| @generate-entities: | ||
| sea-orm-cli generate entity --database-url=mysql://community:community@localhost:3307/community --with-serde both -o src/entities |
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.
🚨 issue (security): Hard-coded DB credentials and connection string should be externalized
--database-url=mysql://community:community@localhost:3307/community embeds credentials and connection details directly in the Justfile, which is risky even for local use if the file is shared or checked in. Use an environment variable or .env value (e.g. DATABASE_URL) and reference it in the Justfile (e.g. --database-url=${DATABASE_URL}) instead of hard-coding secrets and host/port details.
| target_dir = input("Enter directory to create Justfile in: ").strip() | ||
|
|
||
| if not target_dir: |
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.
suggestion: Using interactive input only may limit automation and scriptability
Because this is under scripts/, it may be used in automated flows (e.g. project bootstrap). Requiring interactive input() only makes that difficult. Please also accept the target directory as a CLI argument (e.g. via sys.argv/argparse), and only prompt with input() when no argument is given, so it remains usable both interactively and in automation.
Suggested implementation:
def main():
# Prefer CLI argument for automation; fall back to interactive prompt
if len(sys.argv) > 1:
target_dir = sys.argv[1].strip()
else:
target_dir = input("Enter directory to create Justfile in: ").strip()
if not target_dir:
print("Error: No directory provided")
sys.exit(1)- Ensure
import sysis present at the top ofscripts/create-axum-justfile.py(andimport osif not already imported), sincesys.argvandos.pathare used. - If this script is intended to be run as a module, confirm there is a
if __name__ == "__main__": main()block so the new CLI behavior is used when executed directly.
Summary by Sourcery
Add a helper script to generate a standard Justfile for an Axum project with Docker and SeaORM workflow commands.
New Features:
Enhancements: