Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
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
16 changes: 16 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 17
distribution: 'adopt'
- name: Build with Gradle
run: ./gradlew build
- name: Test with Gradle
run: ./gradlew test
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# sd-homework
# simplecli

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает только инструкции по запуску. -0.5.


Implemented build-ins:
- [cat](src/main/java/ru/itmo/simplecli/executor/constructors/Cat.java)
- [echo](src/main/java/ru/itmo/simplecli/executor/constructors/Echo.java)
- [exit](src/main/java/ru/itmo/simplecli/executor/constructors/Exit.java)
- [grep](src/main/java/ru/itmo/simplecli/executor/constructors/Grep.java)
- [pwd](src/main/java/ru/itmo/simplecli/executor/constructors/Pwd.java)
- [wc](src/main/java/ru/itmo/simplecli/executor/constructors/WC.java)
- [variable assignment](src/main/java/ru/itmo/simplecli/executor/constructors/Assignment.java)

[Main](src/main/java/ru/itmo/simplecli/Main.java) runs loop until `exit` command is given.
If the entered string contains incomplete quotes, it asks to continue typing.

[Parser](src/main/java/ru/itmo/simplecli/executor/Parser.java) supports double and single quotes.
It also performs substitution for values beginning with `$` if it is not surrounded by single quotes.

The CLI [supports](src/main/java/ru/itmo/simplecli/executor/PipedCommand.java) a pipeline of commands, separated by a sign `|`,
each command receives as input the output of the previous one.
26 changes: 26 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
java
}

group = "org.example"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут и в версии можно было бы что-нибудь написать)

version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
implementation("commons-cli:commons-cli:1.5.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

tasks.test {
useJUnitPlatform()
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
185 changes: 185 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = "simplecli"

45 changes: 45 additions & 0 deletions src/main/java/ru/itmo/simplecli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ru.itmo.simplecli;

import ru.itmo.simplecli.executor.*;

import java.util.*;

/**
* Entry point. Loop: read - parse - execute.
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
EnvironmentManager environment = new EnvironmentManager();
Parser parser = new Parser(environment);

while (true) {
System.out.print(">> ");
String input = scanner.nextLine();
if (input.trim().equals("")) {
continue;
}

parser.parse(input);
while (parser.hasUnclosedQuote()) {
System.out.print("> ");
input = input + scanner.nextLine();
parser.parse(input);
}

var command = PipedCommandFactory.construct(parser.getResult(), environment);
if (command == null) {
System.out.println("Can't construct command");
continue;
}

command.execute(null);
if (command.getEndStatus() == Executable.EndStatus.EXIT) {
break;
}
if (command.getOutput() != null) {
System.out.println(command.getOutput());
}
}
}
}
Loading