Skip to content

Commit c20bab6

Browse files
authored
[#5] Add docstrings to feature/lint-fixes
2 parents 3c51c46 + 2e548d6 commit c20bab6

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/interactive.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {
1515
import { logAction } from './logger';
1616
import { configureSshKey } from './lagoon-ssh-key-configurator';
1717

18+
/**
19+
* Launches the interactive Lagoon CLI wrapper, allowing users to manage projects and environments through a guided command-line interface.
20+
*
21+
* Presents menus for selecting Lagoon instances and projects, and provides options to list environments or users, delete environments, generate login links, clear Drupal cache, configure SSH keys, and change selections. Handles errors gracefully and logs major actions throughout the session.
22+
*/
1823
export async function startInteractiveMode() {
1924
console.log(chalk.green('Welcome to the Lagoon CLI Wrapper!'));
2025
logAction('Application Start', 'N/A', 'Interactive mode started');
@@ -152,6 +157,13 @@ async function selectProjectWithDetails(instance) {
152157
};
153158
}
154159

160+
/**
161+
* Displays the main menu for the interactive CLI and prompts the user to select an action.
162+
*
163+
* @param {string} instance - The name of the currently selected Lagoon instance.
164+
* @param {string} project - The name of the currently selected project.
165+
* @returns {Promise<string>} The action selected by the user.
166+
*/
155167
async function showMainMenu(instance, project) {
156168
console.log(chalk.blue(`\nCurrent Instance: ${chalk.bold(instance)}`));
157169
console.log(chalk.blue(`Current Project: ${chalk.bold(project)}\n`));

src/lagoon-api.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,18 @@ export async function getUsers(instance, project) {
114114
}
115115
}
116116

117-
// Delete an environment
117+
/**
118+
* Deletes a Lagoon environment unless it is protected.
119+
*
120+
* Throws an error if the environment is protected (such as 'production', 'master', 'develop', or names starting with 'project/'). Executes the Lagoon CLI to delete the specified environment and returns true if successful.
121+
*
122+
* @param {string} instance - The Lagoon instance name.
123+
* @param {string} project - The project name.
124+
* @param {string} environment - The environment name to delete.
125+
* @returns {boolean} True if the environment was deleted successfully.
126+
*
127+
* @throws {Error} If the environment is protected or if the deletion fails.
128+
*/
118129
export async function deleteEnvironment(instance, project, environment) {
119130
// Check if environment is protected
120131
if (
@@ -158,7 +169,12 @@ export async function generateLoginLink(instance, project, environment) {
158169
}
159170
}
160171

161-
// Helper function to convert git URL to GitHub URL
172+
/**
173+
* Converts a Git SSH or HTTPS URL to a standard GitHub HTTPS URL without the `.git` suffix.
174+
*
175+
* @param {string} gitUrl - The Git repository URL to convert.
176+
* @returns {string|null} The corresponding GitHub HTTPS URL, or {@code null} if the input is not a GitHub URL.
177+
*/
162178
export function gitUrlToGithubUrl(gitUrl) {
163179
// Handle SSH URLs like git@github.com:org/repo.git
164180
if (gitUrl.startsWith('git@github.com:')) {

src/logger.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ function getLogFilePath() {
2222
}
2323

2424
/**
25-
* Log a message to the daily log file
26-
* @param {string} action - The action being performed in the CLI
27-
* @param {string} command - The Lagoon CLI command being executed
28-
* @param {string} [result] - Optional result of the command
25+
* Appends an action entry with timestamp, action, command, and optional result to the current day's log file.
26+
*
27+
* @param {string} action - Description of the action performed.
28+
* @param {string} command - The CLI command executed.
29+
* @param {string} [result] - Optional result of the command.
2930
*/
3031
export function logAction(action, command, result = null) {
3132
const timestamp = new Date().toISOString(); // ISO8601 timestamp
@@ -37,10 +38,11 @@ export function logAction(action, command, result = null) {
3738
}
3839

3940
/**
40-
* Log an error to the daily log file
41-
* @param {string} action - The action being performed in the CLI
42-
* @param {string} command - The Lagoon CLI command being executed
43-
* @param {Error} error - The error that occurred
41+
* Appends an error entry to the current day's log file with a timestamp, action, command, and error message.
42+
*
43+
* @param {string} action - Description of the action being performed.
44+
* @param {string} command - The CLI command that was executed.
45+
* @param {Error} error - The error encountered during execution.
4446
*/
4547
export function logError(action, command, error) {
4648
const timestamp = new Date().toISOString(); // ISO8601 timestamp

0 commit comments

Comments
 (0)