Skip to content

Commit

Permalink
merge: #992
Browse files Browse the repository at this point in the history
992: Respect `--pretty-dir` for libraries r=imkiva a=imkiva

In the past, the literated library is always saved to `<project-root>/build/pretty`. Now we can specify the output location through `--pretty-dir`

Co-authored-by: imkiva <imkiva@islovely.icu>
  • Loading branch information
bors[bot] and imkiva authored Aug 9, 2023
2 parents bd05586 + 170f946 commit 4c9a4fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static class Action {
public PrettyStage prettyStage;
@Option(names = {"--pretty-format"}, description = "Pretty print format." + CANDIDATES, defaultValue = "markdown")
public PrettyFormat prettyFormat;
@Option(names = {"--pretty-dir"}, description = "Specify output directory of pretty printing.", defaultValue = ".")
@Option(names = {"--pretty-dir"}, description = "Specify output directory of pretty printing.")
public String prettyDir;
@Option(names = {"--pretty-color"}, description = "The color theme of pretty printing." + CANDIDATES, defaultValue = "emacs")
public PredefinedStyle prettyColor;
Expand Down
16 changes: 11 additions & 5 deletions cli-impl/src/main/java/org/aya/cli/library/LibraryCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,26 @@ private void resolveImportsIfNeeded(@NotNull LibrarySource source) throws IOExce

public int start() throws IOException {
if (flags.modulePaths().isNotEmpty()) reporter.reportString(
"Warning: command-line specified module path is ignored when compiling libraries.");
if (flags.prettyInfo() != null) reporter.reportString(
"Warning: command-line specified pretty info is ignored when compiling libraries.");
"Warning: command-line specified module path (--module-path) is ignored when compiling libraries.");
if (flags.outputFile() != null) reporter.reportString(
"Warning: command-line specified output file (-o, --output) is ignored when compiling libraries.");
return CompilerUtil.catching(reporter, flags, this::make);
}

private void pretty(ImmutableSeq<LibrarySource> modified) throws IOException {
var cmdPretty = flags.prettyInfo();
if (cmdPretty == null || cmdPretty.prettyStage() != CliEnums.PrettyStage.literate) return;
if (cmdPretty == null) return;
if (cmdPretty.prettyStage() != CliEnums.PrettyStage.literate) {
reporter.reportString("Warning: only 'literate' pretty stage is supported when compiling libraries.");
return;
}

// prepare literate output path
reportNest("[Info] Generating literate output");
var litConfig = owner.underlyingLibrary().literateConfig();
var outputDir = Files.createDirectories(litConfig.outputPath());
var outputDir = cmdPretty.prettyDir() != null
? Files.createDirectories(Path.of(cmdPretty.prettyDir()))
: Files.createDirectories(litConfig.outputPath());

// If the library specifies no literate options, use the ones from the command line.
var litPretty = litConfig.pretty();
Expand Down

0 comments on commit 4c9a4fd

Please sign in to comment.