Skip to content

Commit

Permalink
feat: add edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
imLymei committed Sep 16, 2024
1 parent f2855ab commit ef93ee2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/commands/editCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Command } from 'commander';
import { editConfigCommand } from '../lib/utils';

const editCommand = new Command('edit')
.alias('e')
.description('Edit a foji command')
.argument('name', 'Command name')
.argument('command', 'Command to be added')
.action((name: string, command: string) => {
editConfigCommand(name, command);
});

export default editCommand;
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../lib/utils';
import syncConfig from './syncConfig';
import renameCommand from './renameCommand';
import editCommand from './editCommand';

const program = new Command()
.argument('[command]', 'Command that you want to run')
Expand Down Expand Up @@ -83,6 +84,7 @@ program

program.addCommand(addCommand);
program.addCommand(renameCommand);
program.addCommand(editCommand);
program.addCommand(removeCommand);
program.addCommand(openConfig);
program.addCommand(uploadConfig);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export async function addConfigCommand(key: string, command: string) {
createConfig(newConfig);
}

export async function editConfigCommand(key: string, command: string) {
const newConfig: Config = getConfig();

if (!newConfig.commands[key]) {
console.error('Command not found');
process.exit(1);
}

newConfig.commands[key] = command;

createConfig(newConfig);
}

export function changeGistUrl(newUrl: string) {
const newConfig: Config = getConfig();

Expand Down

0 comments on commit ef93ee2

Please sign in to comment.