Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | 3x 3x 3x 21x 21x 21x 21x 26x 26x 7x 7x 2x 2x 5x 5x 4x 5x 19x 3x 16x 1x 15x 3x 12x 4x 4x 2x 2x 2x 2x 8x 2x 6x 4x 4x 2x 2x 2x 2x 15x 1x 15x 3x 17x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 10x 10x 3x 10x 3x 1x 2x 1x 1x 1x 1x 3x 10x 2x 10x 1x 10x 1x 10x 1x 2x 2x 1x 1x 10x 16x 7x 7x 3x 7x 2x 7x 1x 7x 1x 7x 1x 1x 1x 1x 1x 7x 16x 16x 10x 16x 7x | /**
* CLI utility functions for main entry point
* Extracted for testability
*/
import { logger } from "./logger";
import { getProjectConfigSummary, ProjectConfig } from "./profiles";
/**
* CLI arguments parsed from command line
*/
export interface CliArgs {
profileName?: string;
noProjectConfig: boolean;
showProjectConfig: boolean;
/** Enable auto-discovery from git remote */
auto: boolean;
/** Custom working directory for auto-discovery */
cwd?: string;
/** Dry run - show what would be detected without applying */
dryRun: boolean;
/** Git remote name to use (default: origin) */
remoteName?: string;
}
/**
* Parse CLI arguments
* @param argv - process.argv array (or mock for testing)
* @returns Parsed CLI arguments
*/
export function parseCliArgs(argv: string[] = process.argv): CliArgs {
const args = argv.slice(2);
const result: CliArgs = {
noProjectConfig: false,
showProjectConfig: false,
auto: false,
dryRun: false,
};
let profileCount = 0;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === "--profile") {
const value = args[i + 1];
// Validate that value exists and is not another flag
if (!value || value.startsWith("--")) {
logger.error("--profile requires a profile name (e.g., --profile work)");
throw new Error("--profile requires a profile name");
}
profileCount++;
if (profileCount === 1) {
result.profileName = value;
}
i++; // Skip value
} else if (arg === "--no-project-config") {
result.noProjectConfig = true;
} else if (arg === "--show-project-config") {
result.showProjectConfig = true;
} else if (arg === "--auto") {
result.auto = true;
} else if (arg === "--cwd") {
const value = args[i + 1];
if (!value || value.startsWith("--")) {
logger.error("--cwd requires a directory path (e.g., --cwd /path/to/repo)");
throw new Error("--cwd requires a directory path");
}
result.cwd = value;
i++; // Skip value
} else if (arg === "--dry-run") {
result.dryRun = true;
} else if (arg === "--remote") {
const value = args[i + 1];
if (!value || value.startsWith("--")) {
logger.error("--remote requires a remote name (e.g., --remote upstream)");
throw new Error("--remote requires a remote name");
}
result.remoteName = value;
i++; // Skip value
}
}
if (profileCount > 1) {
logger.warn({ count: profileCount }, "Multiple --profile flags detected, using first value");
}
return result;
}
/**
* Display project configuration to console
* @param config - Project configuration or null
* @param output - Output function (default: console.log, can be mocked for testing)
*/
export function displayProjectConfig(
config: ProjectConfig | null,
output: (msg: string) => void = console.log
): void {
if (!config) {
output("No project configuration found in current directory or parent directories.");
output("\nTo create a project config, add .gitlab-mcp/ directory with:");
output(" - preset.yaml (restrictions: scope, denied_actions, features)");
output(" - profile.yaml (tool selection: extends, additional_tools)");
return;
}
const summary = getProjectConfigSummary(config);
output("Project Configuration");
output("=====================");
output(`Path: ${config.configPath}`);
output("");
if (config.preset) {
output("Preset (restrictions):");
if (config.preset.description) {
output(` Description: ${config.preset.description}`);
}
if (config.preset.scope) {
if (config.preset.scope.project) {
output(` Scope: project "${config.preset.scope.project}"`);
} else if (config.preset.scope.namespace) {
output(` Scope: namespace "${config.preset.scope.namespace}/*"`);
} else Eif (config.preset.scope.projects) {
output(` Scope: ${config.preset.scope.projects.length} projects`);
for (const p of config.preset.scope.projects) {
output(` - ${p}`);
}
}
}
if (config.preset.read_only) {
output(" Read-only: yes");
}
if (config.preset.denied_actions?.length) {
output(` Denied actions: ${config.preset.denied_actions.join(", ")}`);
}
if (config.preset.denied_tools?.length) {
output(` Denied tools: ${config.preset.denied_tools.join(", ")}`);
}
if (config.preset.features) {
const features = Object.entries(config.preset.features)
.filter(([, v]) => v !== undefined)
.map(([k, v]) => `${k}=${v}`)
.join(", ");
Eif (features) {
output(` Features: ${features}`);
}
}
output("");
}
if (config.profile) {
output("Profile (tool selection):");
if (config.profile.description) {
output(` Description: ${config.profile.description}`);
}
if (config.profile.extends) {
output(` Extends: ${config.profile.extends}`);
}
if (config.profile.additional_tools?.length) {
output(` Additional tools: ${config.profile.additional_tools.join(", ")}`);
}
if (config.profile.denied_tools?.length) {
output(` Denied tools: ${config.profile.denied_tools.join(", ")}`);
}
if (config.profile.features) {
const features = Object.entries(config.profile.features)
.filter(([, v]) => v !== undefined)
.map(([k, v]) => `${k}=${v}`)
.join(", ");
Eif (features) {
output(` Features: ${features}`);
}
}
output("");
}
output("Summary:");
if (summary.presetSummary) {
output(` Preset: ${summary.presetSummary}`);
}
if (summary.profileSummary) {
output(` Profile: ${summary.profileSummary}`);
}
}
|