Skip to content

Console

Pedro12909 edited this page Jan 27, 2019 · 3 revisions

Console

The console UI uses the implemented operations of the file system to allow the user to interact with it.

The ConsoleUI.java class has a static variable that stores the current directory the user is in. Every time it changes (by using the command cd) it is updated.

In order to process user input and commands, the Strategy pattern was implemented to allow new features to be added easily in the feature.

    static {
        commands.put("cd", new ChangeDir());
        commands.put("cp", new Copy());
        commands.put("mv", new Move());
        commands.put("ls", new ListDir());
        commands.put("touch", new CreateFile());
        commands.put("mkdir", new CreateFolder());
        commands.put("rm", new Delete());
        commands.put("cat", new ShowFileContent());
    }

Available Commands

Change Directory

Used to navigate inside the file structure

Usage:

cd .. - goes back one level

cd <relative path of folder> - navigated to the folder specified

Create File

Creates a new File with a given name and contents in the current directory

Usage: touch <name of file> <file contents>

Make Directory

Creates a new Folder with a given name in the current directory

Usage: mkdir <name of folder

Copy

Needs to be used in the same path as the item that's going to be copied

Usage: cp <relative path of item to be copied> <absolute path of destination folder>

Move

Moves one item from one location to another destination

Usage: mv <relative path of item to be copied> <absolute path of destination folder>

Remove

Deletes one item from the current directory

Usage: rm <relative path of item to be deleted>

List

Lists all items in the current directory and shows additional information about each one

Usage: ls

Show File Contents

Shows the text contents of a given file.

Usage: cat <relative path of the desired file>

Clone this wiki locally