diff --git a/bin/commands/issue.js b/bin/commands/issue.js index 3d0a661..63b92f6 100644 --- a/bin/commands/issue.js +++ b/bin/commands/issue.js @@ -11,46 +11,7 @@ const path = require('path'); function createIssueCommand(factory) { const command = new Command('issue') .description('Manage JIRA issues') - .alias('i') - .option('-l, --list', 'list issues') - .option('-c, --create', 'create a new issue') - .option('-g, --get ', 'get issue by key') - .option('-u, --update ', 'update issue by key') - .option('-d, --delete ', 'delete issue by key') - .option('--project ', 'filter by project') - .option('--assignee ', 'filter by assignee') - .option('--status ', 'filter by status') - .option('--type ', 'filter by issue type') - .option('--summary ', 'issue summary (for create/update)') - .option('--description ', 'issue description (for create/update)') - .option('--priority ', 'priority (for create/update)') - .option('--limit ', 'limit number of results', '20') - .action(async (options) => { - const io = factory.getIOStreams(); - const client = await factory.getJiraClient(); - const analytics = factory.getAnalytics(); - - try { - await analytics.track('issue', { action: getIssueAction(options) }); - - if (options.create) { - await createIssue(client, io, factory, options); - } else if (options.get) { - await getIssue(client, io, options.get); - } else if (options.update) { - await updateIssue(client, io, options.update, options); - } else if (options.delete) { - await deleteIssue(client, io, options.delete, options); - } else { - // Default to list issues - await listIssues(client, io, options); - } - - } catch (err) { - io.error(`Issue command failed: ${err.message}`); - process.exit(1); - } - }); + .alias('i'); // Add subcommands command @@ -75,7 +36,7 @@ function createIssueCommand(factory) { .action(async (options) => { const io = factory.getIOStreams(); const client = await factory.getJiraClient(); - + try { await listIssues(client, io, options); } catch (err) { @@ -399,12 +360,4 @@ async function deleteIssue(client, io, issueKey, options = {}) { io.success(`Issue ${issueKey} deleted successfully`); } -function getIssueAction(options) { - if (options.create) return 'create'; - if (options.get) return 'get'; - if (options.update) return 'update'; - if (options.delete) return 'delete'; - return 'list'; -} - module.exports = createIssueCommand; diff --git a/tests/commands/issue.test.js b/tests/commands/issue.test.js index da7f2ce..84f860c 100644 --- a/tests/commands/issue.test.js +++ b/tests/commands/issue.test.js @@ -54,40 +54,43 @@ describe('IssueCommand', () => { expect(issueCommand.aliases()).toContain('i'); }); - it('should have options', () => { - const options = issueCommand.options; - expect(options.length).toBeGreaterThan(0); - }); - }); + it('should have subcommands', () => { + const commands = issueCommand.commands; + expect(commands.length).toBeGreaterThan(0); - describe('command options', () => { - it('should have list option', () => { - const listOption = issueCommand.options.find(opt => opt.long === '--list'); - expect(listOption).toBeDefined(); - expect(listOption.short).toBe('-l'); - }); + const listCommand = commands.find(cmd => cmd.name() === 'list'); + expect(listCommand).toBeDefined(); - it('should have create option', () => { - const createOption = issueCommand.options.find(opt => opt.long === '--create'); - expect(createOption).toBeDefined(); - expect(createOption.short).toBe('-c'); + const createCommand = commands.find(cmd => cmd.name() === 'create'); + expect(createCommand).toBeDefined(); + + const viewCommand = commands.find(cmd => cmd.name() === 'view'); + expect(viewCommand).toBeDefined(); }); + }); - it('should have get option', () => { - const getOption = issueCommand.options.find(opt => opt.long === '--get'); - expect(getOption).toBeDefined(); - expect(getOption.short).toBe('-g'); + describe('list subcommand options', () => { + let listCommand; + + beforeEach(() => { + listCommand = issueCommand.commands.find(cmd => cmd.name() === 'list'); }); it('should have filter options', () => { - const projectOption = issueCommand.options.find(opt => opt.long === '--project'); + const projectOption = listCommand.options.find(opt => opt.long === '--project'); expect(projectOption).toBeDefined(); - - const assigneeOption = issueCommand.options.find(opt => opt.long === '--assignee'); + + const assigneeOption = listCommand.options.find(opt => opt.long === '--assignee'); expect(assigneeOption).toBeDefined(); - - const statusOption = issueCommand.options.find(opt => opt.long === '--status'); + + const statusOption = listCommand.options.find(opt => opt.long === '--status'); expect(statusOption).toBeDefined(); }); + + it('should have limit option with default value', () => { + const limitOption = listCommand.options.find(opt => opt.long === '--limit'); + expect(limitOption).toBeDefined(); + expect(limitOption.defaultValue).toBe('20'); + }); }); });