|
| 1 | +# Recipes |
| 2 | + |
| 3 | +This page collects task-oriented workflows for common `py-moodle` jobs. |
| 4 | +Use these recipes when you want a copy/paste starting point instead of a full |
| 5 | +command reference. |
| 6 | + |
| 7 | +## Verify your environment and login |
| 8 | + |
| 9 | +Use this recipe first when setting up a new `.env` profile or switching to a |
| 10 | +different Moodle environment. |
| 11 | + |
| 12 | +```bash |
| 13 | +# Use the environment from MOODLE_ENV or pass one explicitly. |
| 14 | +py-moodle --env local site info |
| 15 | +``` |
| 16 | + |
| 17 | +If the command succeeds, your credentials, session bootstrap, and base URL are |
| 18 | +working together. |
| 19 | + |
| 20 | +If it fails: |
| 21 | + |
| 22 | +- confirm the selected environment name matches your `.env` keys |
| 23 | +- verify `MOODLE_<ENV>_URL`, `MOODLE_<ENV>_USERNAME`, and |
| 24 | + `MOODLE_<ENV>_PASSWORD` |
| 25 | +- review the [Troubleshooting](troubleshooting.md) guide for common login and |
| 26 | + session failures |
| 27 | + |
| 28 | +## Inspect a course before changing it |
| 29 | + |
| 30 | +Use these commands together when you need to confirm IDs and current state |
| 31 | +before creating or deleting content. |
| 32 | + |
| 33 | +```bash |
| 34 | +# Find the course ID you want to work with. |
| 35 | +py-moodle courses list |
| 36 | + |
| 37 | +# Inspect one course in detail. |
| 38 | +py-moodle courses show 2 |
| 39 | + |
| 40 | +# List its sections before adding modules. |
| 41 | +py-moodle sections list 2 |
| 42 | +``` |
| 43 | + |
| 44 | +This flow is useful for scripts and manual operations because it reduces the |
| 45 | +chance of targeting the wrong course or section. |
| 46 | + |
| 47 | +## Create a course and add a welcome label |
| 48 | + |
| 49 | +This is a minimal end-to-end content bootstrap workflow. |
| 50 | + |
| 51 | +```bash |
| 52 | +# 1. Create the course. |
| 53 | +py-moodle courses create \ |
| 54 | + --fullname "Automation Demo" \ |
| 55 | + --shortname "automation-demo" |
| 56 | + |
| 57 | +# 2. Create a section if you need one beyond the default course layout. |
| 58 | +py-moodle sections create 2 --name "Getting Started" |
| 59 | + |
| 60 | +# 3. Add a welcome label to the first section. |
| 61 | +py-moodle modules add label \ |
| 62 | + --course-id 2 \ |
| 63 | + --section-id 1 \ |
| 64 | + --name "Welcome" \ |
| 65 | + --intro "<p>Welcome to the course.</p>" |
| 66 | +``` |
| 67 | + |
| 68 | +Replace the example course ID with the ID returned by the create command in |
| 69 | +your environment. |
| 70 | + |
| 71 | +## Upload materials into a folder |
| 72 | + |
| 73 | +Use the dedicated folder commands when you want to manage a reusable course |
| 74 | +materials area. |
| 75 | + |
| 76 | +```bash |
| 77 | +# Create a folder activity in the course. |
| 78 | +py-moodle folders add \ |
| 79 | + --course-id 2 \ |
| 80 | + --section-id 1 \ |
| 81 | + --name "Course Materials" |
| 82 | + |
| 83 | +# Upload a file into the folder activity. |
| 84 | +py-moodle folders add-file 15 ./docs/syllabus.pdf |
| 85 | + |
| 86 | +# Confirm the folder contents. |
| 87 | +py-moodle folders list-content 15 |
| 88 | +``` |
| 89 | + |
| 90 | +In this recipe, `15` is the folder module ID returned by the add command. |
| 91 | + |
| 92 | +## Run the fastest contributor validation loop |
| 93 | + |
| 94 | +When you are changing code or documentation, this sequence gives the quickest |
| 95 | +feedback with the existing repository tooling. |
| 96 | + |
| 97 | +```bash |
| 98 | +# Fast smoke tests with no live Moodle requirement. |
| 99 | +make test-unit |
| 100 | + |
| 101 | +# Static checks used by CI. |
| 102 | +make lint |
| 103 | + |
| 104 | +# Rebuild the documentation site, including generated CLI docs. |
| 105 | +make docs |
| 106 | +``` |
| 107 | + |
| 108 | +Use `make test-local` only when you need Docker-backed integration coverage |
| 109 | +against the local Moodle environment. |
0 commit comments