Skip to content

Commit

Permalink
feat: add run command
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves authored Apr 8, 2024
1 parent faed989 commit 116fd6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import * as fs from 'fs';
import * as exec from '@cloud-cli/exec';
import sys from './index';

Expand All @@ -20,6 +20,16 @@ describe('system commands', () => {
expect(exec.exec).toHaveBeenCalledWith('npm', ['i', '@cloud-cli/test']);
});

it('should run a command', async () => {
jest
.spyOn(exec, 'execString')
.mockReset()
.mockImplementationOnce(async () => execOutput);

await expect(sys.run({ c: 'ls -al' })).resolves.toBe('');
expect(exec.execString).toHaveBeenCalledWith('ls -al');
});

it('should update all modules', async () => {
jest
.spyOn(exec, 'exec')
Expand Down
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { exec } from '@cloud-cli/exec';
import fs from 'fs';
import { exec, execString } from '@cloud-cli/exec';
import * as fs from 'fs';

interface InstallOptions { m: string }
interface RunOptions { c: string }

async function update() {
`Update dependencies`;
Expand All @@ -25,6 +26,13 @@ async function restart() {
return true;
}

async function run({ c }: RunOptions) {
`Run a commmand`;

const o = await execString(c);
return o.ok ? o.stdout : Promise.reject(o.stderr);
}

function createService() {
`Generate a systemd template for Cloudy`;

Expand Down Expand Up @@ -70,4 +78,4 @@ async function logs(options) {
return o.stdout;
}

export default { update, install, restart, createService, logs, stats };
export default { update, install, restart, createService, logs, stats, run };

0 comments on commit 116fd6f

Please sign in to comment.