Skip to content

Commit

Permalink
Merge pull request #4 from kleis-technology/feature/cli
Browse files Browse the repository at this point in the history
Feature/cli
  • Loading branch information
pevab authored Jan 17, 2024
2 parents 40f38bf + 7307eab commit 0b3d798
Show file tree
Hide file tree
Showing 18 changed files with 4,820 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .autoenv.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash

export GIT_ROOT=$(git rev-parse --show-toplevel)
function lcaac() {
$GIT_ROOT/cli/build/install/cli/bin/cli $@
}
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,59 @@ Its *declarative* approach enables to seamlessly define *parametrized* and *reus

![LCA as Code](./assets/logo-white-60pct.png)

## Table of Contents

1. [Getting started](#getting-started)
2. [What's inside](#whats-inside)
3. [Related projects](#related-projects)
4. [License](#license)
5. [About us](#about-us)

## Getting started

Check the sample file in `$GIT_ROOT/cli/samples`.

```lca
process electricity_production_mix {
process electricity_mix {
params {
hydro = 20 percent
nuclear = 30 percent
fossil = 50 percent
from_fossil = 40 percent
from_nuclear = 20 percent
from_hydro = 40 percent
}
products {
1 kWh electricity
}
inputs {
hydro * 1 kWh electricity from hydroelectric_production
nuclear * 1 kWh electricity from nuclear_production
fossil * 1 kWh electricity from fossil_production
from_fossil * 1 kWh electricity from fossil
from_nuclear * 1 kWh electricity from nuclear
from_hydro * 1 kWh electricity from hydro
}
}
// rest of the file omitted
```

## Table of Contents
On the command line, setup the cli.
```bash
./gradlew :cli:installDist
alias lcaac=$GIT_ROOT/cli/build/install/cli/bin/cli
```

Now you can assess the process `electricity_mix`.
```bash
cd $GIT_ROOT/cli/samples
lcaac assess "electricity_mix"
```
The result is printed on the standard output in CSV format.
```csv
product,amount,reference unit,co2 [kg]
electricity,1.0,kWh,5.4
```

You can also run multiple assessments with an external data csv file providing values for the process parameters.
```bash
lcaac assess "electricity_mix" --data params.csv
```

1. [What's inside](#whats-inside)
2. [Related projects](#related-projects)
3. [License](#license)
4. [About us](#about-us)

## What's inside

Expand All @@ -54,6 +83,10 @@ The package `grammar` contains:
- a concrete ANTLR-based grammar
- utilities to parse and load LCAAC files.

### Package `cli`

The package `cli` contains the code for the command-line interface.

## Related projects

### Cloud Assess
Expand Down
30 changes: 30 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# LCAAC Command-Line Interface

## Set-up

```bash
./gradlew :cli:installDist
alias lcaac=$GIT_ROOT/cli/build/install/cli/bin/cli
```

## Impact assessment

The `assess` command runs the impact assessment of a target process.
The results are printed on the standard output in CSV format.

```bash
cd $GIT_ROOT/cli/samples
lcaac assess "electricity_mix"
```

```bash
cd $GIT_ROOT/cli/samples
lcaac assess "electricity_mix" --data params.csv
```

## Help

```bash
lcaac --help
lcaac assess --help
```
70 changes: 70 additions & 0 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
fun properties(key: String) = project.findProperty(key).toString()

plugins {
application
`maven-publish`
id("org.jetbrains.kotlin.jvm")
}

val groupId = properties("lcaacGroup")
val artifactId = "cli"
val artifactVersion = properties("lcaacVersion")
val javaVersion = properties("javaVersion")

application {
mainClass.set("ch.kleis.lcaac.cli.MainKt")
}

kotlin {
jvmToolchain(Integer.parseInt(javaVersion))
}

repositories {
mavenCentral()
}

dependencies {
implementation(project(":core"))
testImplementation(project(":core"))

implementation(project(":grammar"))
testImplementation(project(":grammar"))

testImplementation("io.mockk:mockk:1.13.4")
implementation(kotlin("stdlib-jdk8"))

val log4jVersion = "2.20.0"
implementation("org.apache.logging.log4j:log4j-api:$log4jVersion")
implementation("org.apache.logging.log4j:log4j-core:$log4jVersion")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion")

testImplementation(kotlin("test"))

implementation("com.github.ajalt.clikt:clikt:4.2.2")
implementation("org.apache.commons:commons-csv:1.10.0")
}

tasks.test {
useJUnitPlatform()
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/kleis-technology/lcaac")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
create<MavenPublication>("cli") {
groupId = groupId
artifactId = artifactId
version = artifactVersion
from(components["java"])
}
}
}
42 changes: 42 additions & 0 deletions cli/samples/main.lca
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
process electricity_mix {
params {
from_fossil = 40 percent
from_nuclear = 20 percent
from_hydro = 40 percent
}
products {
1 kWh electricity
}
inputs {
from_fossil * 1 kWh electricity from fossil
from_nuclear * 1 kWh electricity from nuclear
from_hydro * 1 kWh electricity from hydro
}
}

process fossil {
products {
1 kWh electricity
}
impacts {
10 kg co2
}
}

process nuclear {
products {
1 kWh electricity
}
impacts {
5 kg co2
}
}

process hydro {
products {
1 kWh electricity
}
impacts {
1 kg co2
}
}
Loading

0 comments on commit 0b3d798

Please sign in to comment.