Skip to content

feat(#9261): add --project-name and --cht-version flags to cht-docker-compose.sh#11098

Open
vikrantwiz02 wants to merge 3 commits into
medic:masterfrom
vikrantwiz02:9261-docker-helper-scripting-args
Open

feat(#9261): add --project-name and --cht-version flags to cht-docker-compose.sh#11098
vikrantwiz02 wants to merge 3 commits into
medic:masterfrom
vikrantwiz02:9261-docker-helper-scripting-args

Conversation

@vikrantwiz02
Copy link
Copy Markdown
Contributor

Description

Closes #9261.

The cht-docker-compose.sh script previously relied entirely on interactive prompts (read -rp, select menus), making it impossible to use in CI/CD pipelines or scripted workflows. This was the root cause of the stdin.write('y\n') workaround in medic/cht-conf#620, which is fragile and breaks any time a prompt is added or removed.

This PR adds two optional flags to the script:

Flag Short Description
--project-name NAME -n Create or start a named project without interactive prompts
--cht-version VERSION -V Specify the CHT version to use (defaults to latest)

New non-interactive usage:

# Create a new project using the latest CHT version
./cht-docker-compose.sh --project-name myproject

# Create a new project with a specific CHT version
./cht-docker-compose.sh --project-name myproject --cht-version 4.10.0

# Start an existing project by name (skips creation if .env already exists)
./cht-docker-compose.sh --project-name myproject

All 4 existing usage patterns are fully preserved (no breaking changes):

./cht-docker-compose.sh                         # interactive (unchanged)
./cht-docker-compose.sh ENV-FILE.env            # start by file (unchanged)
./cht-docker-compose.sh ENV-FILE.env stop       # stop (unchanged)
./cht-docker-compose.sh ENV-FILE.env destroy    # destroy (unchanged)

Implementation details:

  • Argument parsing replaced with a standard while/shift flag loop; flags must precede any positional .env argument (conventional Unix behaviour)
  • Project name is sanitized (lowercased, non-alphanumeric chars replaced with _) matching the existing interactive behaviour
  • If --project-name is given and the .env already exists, the script skips creation and starts the existing project using its existing .env, compose files, and data in $HOME/.medic/cht-docker/
  • --help / -h moved into the flag loop and updated to document the new flags
  • Unknown flags produce an error message and exit 1

Code review checklist

  • UI/UX backwards compatible~~
  • Readable: Concise, well named, follows the style guide
  • Documented: Configuration and user documentation on cht-docs~~
  • Tested: Mocha unit tests added (scripts/docker-helper/tests/cht-docker-compose.spec.js); npm run unit-docker-helper runs 11 tests covering all new flags and backwards-compatible paths; npm run lint passes clean
  • Internationalised~~
  • Backwards compatible: All 4 existing positional usage patterns preserved unchanged; existing .env files, compose files, and project data directories are read without modification
  • AI disclosure: Please disclose use of AI per the guidelines.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@vikrantwiz02
Copy link
Copy Markdown
Contributor Author

@jkuester, it's ready for review. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Docker Helper more scripting friendly

1 participant