@shutootaki/gwm
Version:
git worktree manager CLI
125 lines • 6.8 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* gwm completion コマンドのReactコンポーネント
* install, uninstall, status 等のUI表示を担当
*/
import { useEffect, useState } from 'react';
import { Text, Box } from 'ink';
import { Notice } from './ui/Notice.js';
import { parseInstallArgs, runInstall, parseUninstallArgs, runUninstall, getStatus, formatStatus, parseScriptArgs, runScript, } from '../completion/commands/index.js';
/**
* Completion コンポーネント
*/
export const Completion = ({ subCommand, args }) => {
switch (subCommand) {
case 'script':
return _jsx(CompletionScript, { args: args });
case 'install':
return _jsx(CompletionInstall, { args: args });
case 'uninstall':
return _jsx(CompletionUninstall, { args: args });
case 'status':
return _jsx(CompletionStatus, {});
default:
return _jsx(CompletionHelp, {});
}
};
/**
* script サブコマンド
*/
const CompletionScript = ({ args }) => {
const [error, setError] = useState(null);
useEffect(() => {
const parsedArgs = parseScriptArgs(args);
const success = runScript(parsedArgs);
if (!success) {
setError('--shell option is required (bash, zsh, or fish)');
}
else {
process.exit(0);
}
}, [args]);
if (error) {
return (_jsx(Notice, { variant: "error", title: "Failed to generate completion script", messages: [
error,
'Usage: gwm completion script --shell <bash|zsh|fish>',
] }));
}
return null;
};
/**
* install サブコマンド
*/
const CompletionInstall = ({ args }) => {
const [result, setResult] = useState(null);
useEffect(() => {
const parsedArgs = parseInstallArgs(args);
// どちらのオプションも指定されていない場合
if (!parsedArgs.shell && !parsedArgs.kiro) {
setResult({
success: false,
message: '--shell or --kiro option is required',
});
return;
}
const installResult = runInstall(parsedArgs);
setResult(installResult);
}, [args]);
if (!result) {
return _jsx(Text, { children: "Installing..." });
}
if (!result.success) {
return (_jsx(Notice, { variant: "error", title: "Failed to install completion", messages: [
result.message,
'Usage: gwm completion install --shell <bash|zsh|fish> [--dry-run] [--modify-rc]',
' gwm completion install --kiro [--dry-run]',
] }));
}
return (_jsx(Notice, { variant: "success", title: "Completion installed successfully!", messages: result.message.split('\n').filter(Boolean) }));
};
/**
* uninstall サブコマンド
*/
const CompletionUninstall = ({ args }) => {
const [result, setResult] = useState(null);
useEffect(() => {
const parsedArgs = parseUninstallArgs(args);
// いずれのオプションも指定されていない場合
if (!parsedArgs.shell && !parsedArgs.kiro && !parsedArgs.all) {
setResult({
success: false,
message: '--shell, --kiro, or --all option is required',
});
return;
}
const uninstallResult = runUninstall(parsedArgs);
setResult(uninstallResult);
}, [args]);
if (!result) {
return _jsx(Text, { children: "Uninstalling..." });
}
if (!result.success) {
return (_jsx(Notice, { variant: "error", title: "Failed to uninstall completion", messages: [
result.message,
'Usage: gwm completion uninstall --shell <bash|zsh|fish>',
' gwm completion uninstall --kiro',
' gwm completion uninstall --all',
] }));
}
return (_jsx(Notice, { variant: "success", title: "Completion uninstalled successfully!", messages: result.message.split('\n').filter(Boolean) }));
};
/**
* status サブコマンド
*/
const CompletionStatus = () => {
const statuses = getStatus();
const formatted = formatStatus(statuses);
return (_jsx(Box, { flexDirection: "column", children: formatted.split('\n').map((line, i) => (_jsx(Text, { children: line }, i))) }));
};
/**
* ヘルプ表示
*/
const CompletionHelp = () => {
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Manage shell completion for gwm." }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "USAGE:" }), _jsx(Text, { children: " gwm completion <subcommand> [options]" }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "SUBCOMMANDS:" }), _jsx(Text, { children: " script Output completion script to stdout" }), _jsx(Text, { children: " install Install completion for your shell" }), _jsx(Text, { children: " uninstall Uninstall completion" }), _jsx(Text, { children: " status Show completion installation status" }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "SCRIPT OPTIONS:" }), _jsx(Text, { children: " --shell <bash|zsh|fish> Shell type (required)" }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "INSTALL OPTIONS:" }), _jsx(Text, { children: " --shell <bash|zsh|fish> Shell type" }), _jsx(Text, { children: " --kiro Install Kiro/Fig completion spec" }), _jsx(Text, { children: " --dry-run Show what would be done" }), _jsx(Text, { children: " --modify-rc Modify shell rc file" }), _jsx(Text, { children: " --path <path> Custom installation path" }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "UNINSTALL OPTIONS:" }), _jsx(Text, { children: " --shell <bash|zsh|fish> Shell type" }), _jsx(Text, { children: " --kiro Uninstall Kiro/Fig completion spec" }), _jsx(Text, { children: " --all Uninstall all completions (bash, zsh, fish, kiro)" }), _jsx(Text, {}), _jsx(Text, { bold: true, children: "EXAMPLES:" }), _jsx(Text, { color: "gray", children: " # Install zsh completion" }), _jsx(Text, { children: " $ gwm completion install --shell zsh" }), _jsx(Text, {}), _jsx(Text, { color: "gray", children: " # Install with shell rc modification" }), _jsx(Text, { children: " $ gwm completion install --shell zsh --modify-rc" }), _jsx(Text, {}), _jsx(Text, { color: "gray", children: " # Install Kiro/Fig completion" }), _jsx(Text, { children: " $ gwm completion install --kiro" }), _jsx(Text, {}), _jsx(Text, { color: "gray", children: " # Check installation status" }), _jsx(Text, { children: " $ gwm completion status" }), _jsx(Text, {}), _jsx(Text, { color: "gray", children: " # Output zsh completion script" }), _jsx(Text, { children: " $ gwm completion script --shell zsh" })] }));
};
//# sourceMappingURL=Completion.js.map