-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate wiki markup for updating curator documentation #1018
Draft
arteymix
wants to merge
3
commits into
master
Choose a base branch
from
feature-generate-wiki-markup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
gemma-cli/src/main/java/ubic/gemma/core/util/AbstractCompletionGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ubic.gemma.core.util; | ||
|
||
import org.apache.commons.cli.Options; | ||
import ubic.gemma.core.apps.GemmaCLI; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.PrintWriter; | ||
import java.util.Map; | ||
import java.util.SortedMap; | ||
|
||
public abstract class AbstractCompletionGenerator implements CompletionGenerator { | ||
|
||
protected final Options generalOptions; | ||
private final SortedMap<GemmaCLI.CommandGroup, SortedMap<String, CLI>> commands; | ||
|
||
protected AbstractCompletionGenerator( Options generalOptions, SortedMap<GemmaCLI.CommandGroup, SortedMap<String, CLI>> commands ) { | ||
this.generalOptions = generalOptions; | ||
this.commands = commands; | ||
} | ||
|
||
@Override | ||
public void generateCompletion( PrintWriter completionWriter ) { | ||
generateGeneralCompletion( generalOptions, completionWriter ); | ||
for ( Map.Entry<GemmaCLI.CommandGroup, SortedMap<String, CLI>> group : commands.entrySet() ) { | ||
for ( CLI cli : group.getValue().values() ) { | ||
generateSubcommandCompletion( cli.getCommandName(), cli.getOptions(), cli.getShortDesc(), cli.allowPositionalArguments(), completionWriter ); | ||
} | ||
} | ||
} | ||
|
||
protected abstract void generateGeneralCompletion( Options options, PrintWriter writer ); | ||
|
||
protected abstract void generateSubcommandCompletion( String subcommand, Options subcommandOptions, @Nullable String subcommandDescription, boolean allowsPositionalArguments, PrintWriter writer ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 1 addition & 14 deletions
15
gemma-cli/src/main/java/ubic/gemma/core/util/CompletionGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
package ubic.gemma.core.util; | ||
|
||
import org.apache.commons.cli.Options; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
public interface CompletionGenerator { | ||
|
||
default void beforeCompletion( PrintWriter writer ) { | ||
} | ||
|
||
void generateCompletion( Options options, PrintWriter writer ); | ||
|
||
void generateSubcommandCompletion( String subcommand, Options subcommandOptions, @Nullable String subcommandDescription, boolean allowsPositionalArguments, PrintWriter writer ); | ||
|
||
default void afterCompletion( PrintWriter writer ) { | ||
|
||
} | ||
void generateCompletion( PrintWriter completionWriter ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
gemma-cli/src/main/java/ubic/gemma/core/util/WikiCompletionGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package ubic.gemma.core.util; | ||
|
||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import ubic.gemma.core.apps.GemmaCLI; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.PrintWriter; | ||
import java.util.SortedMap; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Generator that produce Wiki markup to update user documentation at a glance. | ||
* <p> | ||
* This generator specifically produces <a href="https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html">Confluence Wiki Markup</a>. | ||
* @author poirigui | ||
*/ | ||
public class WikiCompletionGenerator extends AbstractCompletionGenerator { | ||
|
||
private final SortedMap<GemmaCLI.CommandGroup, SortedMap<String, CLI>> commands; | ||
|
||
public WikiCompletionGenerator( Options generalOptions, SortedMap<GemmaCLI.CommandGroup, SortedMap<String, CLI>> commands ) { | ||
super( generalOptions, commands ); | ||
this.commands = commands; | ||
} | ||
|
||
@Override | ||
public void generateCompletion( PrintWriter writer ) { | ||
for ( GemmaCLI.CommandGroup commandGroup : commands.keySet() ) { | ||
writer.printf( "h2. %s%n", commandGroup.name() ); | ||
writer.println(); | ||
for ( CLI c : commands.get( commandGroup ).values() ) { | ||
writer.printf( "[%s]%s%n", c.getCommandName(), StringUtils.isNotBlank( c.getShortDesc() ) ? " - " + c.getShortDesc() : "" ); | ||
} | ||
writer.println(); | ||
} | ||
super.generateCompletion( writer ); | ||
} | ||
|
||
@Override | ||
protected void generateGeneralCompletion( Options options, PrintWriter writer ) { | ||
writer.printf( "h2. General Options%n" ); | ||
writer.println(); | ||
generateOptionTable( options, writer ); | ||
} | ||
|
||
@Override | ||
protected void generateSubcommandCompletion( String subcommand, Options subcommandOptions, @Nullable String subcommandDescription, boolean allowsPositionalArguments, PrintWriter writer ) { | ||
writer.printf( "h2. %s%n", subcommand ); | ||
writer.println(); | ||
if ( StringUtils.isNotBlank( subcommandDescription ) ) { | ||
writer.printf( "%s%n", subcommandDescription ); | ||
writer.println(); | ||
} | ||
writer.printf( "{{Usage: gemma-cli %s %s%s}}%n", subcommand, | ||
inlineSummaryOfOptions( subcommandOptions ), | ||
allowsPositionalArguments ? " ARGS..." : "" ); | ||
writer.println(); | ||
generateOptionTable( subcommandOptions, writer ); | ||
} | ||
|
||
private String inlineSummaryOfOptions( Options options ) { | ||
return options.getOptions().stream() | ||
.map( this::inlineSummaryOfOption ) | ||
.collect( Collectors.joining( " " ) ); | ||
} | ||
|
||
private String inlineSummaryOfOption( Option option ) { | ||
StringBuilder sb = new StringBuilder(); | ||
if ( !option.isRequired() ) { | ||
sb.append( '[' ); | ||
} | ||
sb.append( "-" ).append( option.getOpt() ); | ||
if ( option.getLongOpt() != null ) { | ||
sb.append( ",--" ).append( option.getLongOpt() ); | ||
} | ||
if ( option.hasArg() ) { | ||
sb.append( "=" ); | ||
sb.append( option.getArgName() != null ? option.getArgName() : "ARG" ); | ||
} | ||
if ( !option.isRequired() ) { | ||
sb.append( ']' ); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
private void generateOptionTable( Options options, PrintWriter writer ) { | ||
writer.println( "||Flags||Description||" ); | ||
for ( Option option : options.getOptions() ) { | ||
writer.printf( "|{{%s%s}}|%s|%n", "-" + option.getOpt(), | ||
option.getLongOpt() != null ? ",--" + option.getLongOpt() : "", | ||
option.getDescription() ); | ||
} | ||
writer.println(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a single
COMPLETION_SYNTAX_OPTION
would be nicer for covering both shell and wiki?