Skip to content

Commit

Permalink
feat(pwd): add pwd command
Browse files Browse the repository at this point in the history
- shows current drive name, provider and path
- also displays list of drives
  • Loading branch information
gamemaker1 committed May 17, 2021
1 parent d05ea92 commit 3610074
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/commands/pwd.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Command to move into a folder

// Use the chalk library to write colourful text
import Chalk from 'chalk'

// Import all methods from config and utils
import * as Config from '../utils/config.util'
import * as FsUtils from '../utils/fs.util'
// Import the print statement
import { print } from '../utils/general.util'
// Import the logger
import Logger from '../utils/logger.util'

// The cd command
export const run = async (args: string[]): Promise<void> => {
Logger.debug(`command.cd.run: cd called with args: ${args}`)

// Print out the current drive name, type and path
const currentDrive = Config.get('currentDrive') as string

if (!currentDrive) {
throw new Error(`Invalid current drive name`)
}

print(
Chalk.yellow(
`In drive ${Chalk.keyword('orange')(
currentDrive,
)} (${Chalk.keyword('orange')(
Config.get(`drives.${currentDrive}.provider`),
)}); current path: ${Chalk.keyword('orange')(
Config.get(`drives.${currentDrive}.path`) || '/',
)}`,
),
)

// Also print a list of all drives
const drives = Config.get(`drives`) as Record<string, any>

print(Chalk.yellow('\nList of drives:'))
for (const drive of Object.keys(drives)) {
print(
Chalk.yellow(
`- ${Chalk.keyword('orange')(drive)} (${Chalk.keyword('orange')(
Config.get(`drives.${drive}.provider`),
)}); current path: ${Chalk.keyword('orange')(
Config.get(`drives.${drive}.path`) || '/',
)}`,
),
)
}
}
9 changes: 9 additions & 0 deletions src/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Import all commands
import { run as runPwdCommand } from './commands/pwd.command'
import { run as runCdCommand } from './commands/cd.command'
import { run as runListCommand } from './commands/list.command'
import { run as runReadCommand } from './commands/read.command'
Expand Down Expand Up @@ -39,6 +40,14 @@ export default class Shell {
process.env.PROCESSING_COMMAND = 'true'

switch (args[0]) {
case 'pwd':
case 'whereami':
case 'location':
case 'loc':
Logger.debug(`shell.run: running pwd: ${args.slice(1)}`)

await runPwdCommand(args.slice(1))
break
case 'cd':
Logger.debug(`shell.run: running cd: ${args.slice(1)}`)

Expand Down

0 comments on commit 3610074

Please sign in to comment.