Skip to content

Commit

Permalink
add default output to render command (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen authored Nov 5, 2023
1 parent 5c4e3f5 commit 812a700
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jnotebook-core/src/main/java/tech/catheu/jnotebook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.IOException;
import java.nio.file.Paths;

import org.checkerframework.checker.nullness.qual.Nullable;

import static tech.catheu.jnotebook.Constants.VERSION;

@CommandLine.Command(
Expand Down Expand Up @@ -103,7 +105,9 @@ public static class RenderConfiguration extends SharedConfiguration {
description = "The path to the notebook to render.")
public String inputPath;

@CommandLine.Parameters(index = "1", description = "The output path.")

@Nullable
@CommandLine.Parameters(index = "1", arity = "0..1", description = "The output path.")
public String outputPath;

@CommandLine.Option(names= {"--no-optimize"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package tech.catheu.jnotebook;

import com.google.common.io.Files;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
Expand Down Expand Up @@ -84,6 +85,10 @@ public void render(final Main.RenderConfiguration config) {
html = optimizeHtml(html);
}

String outputPath = config.outputPath;
if(outputPath==null) {
outputPath = Files.getNameWithoutExtension(config.inputPath) + ".html";
}
final File outputFile = FileUtils.getFile(config.outputPath);
FileUtils.write(outputFile, html, StandardCharsets.UTF_8);
LOG.info("Notebook rendered successfully and written to {}", outputFile);
Expand Down

0 comments on commit 812a700

Please sign in to comment.