Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add buildable CLI application with Node.js
Co-authored-by: CarlSp8 <249240924+CarlSp8@users.noreply.github.com>
  • Loading branch information
Copilot and CarlSp8 committed Feb 3, 2026
commit 4950609abf2918df43035878485beb3652e267aa
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Dependencies
node_modules/

# Build output
dist/
build/

# OS files
.DS_Store
Thumbs.db

# IDE files
.idea/
.vscode/
*.swp
*.swo

# Environment files
.env
.env.local

# Logs
*.log
npm-debug.log*

# Test coverage
coverage/

# Temporary files
tmp/
temp/
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@github/copilot",
"version": "0.1.0",
"description": "GitHub Copilot CLI brings the power of Copilot coding agent directly to your terminal.",
"main": "src/index.js",
"bin": {
"copilot": "src/index.js"
},
"scripts": {
"start": "node src/index.js",
"build": "echo 'No build step required for this JavaScript CLI'",
"test": "node --test"
},
"keywords": [
"github",
"copilot",
"cli",
"ai",
"assistant"
],
"author": "GitHub",
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
"type": "git",
"url": "https://github.com/github/copilot-cli.git"
},
"homepage": "https://docs.github.com/copilot/concepts/agents/about-copilot-cli",
"engines": {
"node": ">=18.0.0"
}
}
126 changes: 126 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env node

/**
* GitHub Copilot CLI
* Brings the power of GitHub Copilot coding agent directly to your terminal.
*/

const { version, description } = require('../package.json');

const HELP_TEXT = `
GitHub Copilot CLI - ${description}

Usage: copilot [options] [command]

Options:
-h, --help Show this help message
-v, --version Show version number
--banner Show the animated banner on launch
--experimental Enable experimental features

Commands:
/login Authenticate with GitHub
/logout Sign out of GitHub
/model Choose from available AI models
/feedback Submit feedback
/lsp View LSP server status
/experimental Toggle experimental mode

For more information, visit:
https://docs.github.com/copilot/concepts/agents/about-copilot-cli
`;

/**
* Parse command line arguments
* @param {string[]} args - Command line arguments
* @returns {Object} Parsed arguments
*/
function parseArgs(args) {
const parsed = {
help: false,
version: false,
banner: false,
experimental: false,
command: null
};

for (const arg of args) {
switch (arg) {
case '-h':
case '--help':
parsed.help = true;
break;
case '-v':
case '--version':
parsed.version = true;
break;
case '--banner':
parsed.banner = true;
break;
case '--experimental':
parsed.experimental = true;
break;
default:
if (!arg.startsWith('-') && !parsed.command) {
parsed.command = arg;
}
break;
}
}

return parsed;
}

/**
* Main entry point
*/
function main() {
const args = process.argv.slice(2);
const parsed = parseArgs(args);

// Handle version flag first
if (parsed.version) {
console.log(`GitHub Copilot CLI v${version}`);
process.exit(0);
}

// Handle explicit help flag
if (parsed.help) {
console.log(HELP_TEXT);
process.exit(0);
}

// Handle banner option
if (parsed.banner) {
console.log(`
╔═══════════════════════════════════════════════╗
║ ║
║ GitHub Copilot CLI ║
║ ║
║ AI-powered coding assistance in your ║
║ terminal ║
║ ║
╚═══════════════════════════════════════════════╝
`);
}

if (parsed.experimental) {
console.log('Experimental mode enabled.');
}

// If we have a command, display placeholder message
if (parsed.command) {
console.log(`Command "${parsed.command}" is not yet implemented.`);
console.log('For full functionality, please install the complete GitHub Copilot CLI.');
console.log('Run "copilot --help" for more information.');
process.exit(1);
}

// Show help if no arguments provided and no flags were handled
if (args.length === 0) {
console.log(HELP_TEXT);
process.exit(0);
}
}

main();
58 changes: 58 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { describe, it } = require('node:test');
const assert = require('node:assert');
const { execSync } = require('child_process');
const path = require('path');

const CLI_PATH = path.join(__dirname, '..', 'src', 'index.js');

describe('GitHub Copilot CLI', () => {
describe('--version', () => {
it('should display version information', () => {
const output = execSync(`node ${CLI_PATH} --version`, { encoding: 'utf8' });
assert.match(output, /GitHub Copilot CLI v\d+\.\d+\.\d+/);
});
});

describe('--help', () => {
it('should display help information', () => {
const output = execSync(`node ${CLI_PATH} --help`, { encoding: 'utf8' });
assert.ok(output.includes('Usage: copilot [options] [command]'));
assert.ok(output.includes('--help'));
assert.ok(output.includes('--version'));
});
});

describe('-v shorthand', () => {
it('should display version with -v flag', () => {
const output = execSync(`node ${CLI_PATH} -v`, { encoding: 'utf8' });
assert.match(output, /GitHub Copilot CLI v\d+\.\d+\.\d+/);
});
});

describe('-h shorthand', () => {
it('should display help with -h flag', () => {
const output = execSync(`node ${CLI_PATH} -h`, { encoding: 'utf8' });
assert.ok(output.includes('Usage: copilot [options] [command]'));
});
});

describe('--banner', () => {
it('should display banner when --banner flag is used', () => {
const output = execSync(`node ${CLI_PATH} --banner`, { encoding: 'utf8' });
assert.ok(output.includes('GitHub Copilot CLI'));
assert.ok(output.includes('AI-powered coding assistance'));
});

it('should not display help when only --banner flag is used', () => {
const output = execSync(`node ${CLI_PATH} --banner`, { encoding: 'utf8' });
assert.ok(!output.includes('Usage: copilot [options] [command]'));
});
});

describe('no arguments', () => {
it('should display help when no arguments are provided', () => {
const output = execSync(`node ${CLI_PATH}`, { encoding: 'utf8' });
assert.ok(output.includes('Usage: copilot [options] [command]'));
});
});
});