Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
580 additions
and
124 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
community/command-line/src/main/java/org/neo4j/commandline/admin/AdminCommandSection.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,52 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.commandline.admin; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public abstract class AdminCommandSection | ||
{ | ||
private static final AdminCommandSection GENERAL = new GeneralSection(); | ||
|
||
public abstract String printable(); | ||
|
||
public static AdminCommandSection general() | ||
{ | ||
return GENERAL; | ||
} | ||
|
||
public final void printAllCommandsUnderSection( Consumer<String> output, List<AdminCommand.Provider> providers ) | ||
{ | ||
output.accept( printable() ); | ||
providers.sort( Comparator.comparing( AdminCommand.Provider::name ) ); | ||
providers.forEach( provider -> provider.printSummary( s -> output.accept( " " + s ) ) ); | ||
} | ||
|
||
static class GeneralSection extends AdminCommandSection | ||
{ | ||
@Override | ||
public String printable() | ||
{ | ||
return "General"; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
community/command-line/src/main/java/org/neo4j/commandline/admin/CommandUsage.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,52 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.commandline.admin; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.neo4j.commandline.arguments.Arguments; | ||
|
||
import static java.lang.String.format; | ||
|
||
class CommandUsage | ||
{ | ||
private final AdminCommand.Provider command; | ||
private final String scriptName; | ||
|
||
CommandUsage( AdminCommand.Provider command, String scriptName ) | ||
{ | ||
this.command = command; | ||
this.scriptName = scriptName; | ||
} | ||
|
||
void printDetailed( Consumer<String> output ) | ||
{ | ||
for ( Arguments arguments : command.possibleArguments() ) | ||
{ | ||
//Arguments arguments = command.arguments(); | ||
|
||
String left = format( "usage: %s %s", scriptName, command.name() ); | ||
|
||
output.accept( Arguments.rightColumnFormatted( left, arguments.usage(), left.length() + 1 ) ); | ||
} | ||
output.accept( "" ); | ||
output.accept( command.allArguments().description( command.description() ) ); | ||
} | ||
} |
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
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
66 changes: 66 additions & 0 deletions
66
...unity/command-line/src/test/java/org/neo4j/commandline/admin/AdminCommandSectionTest.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,66 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.commandline.admin; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.InOrder; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.mockito.Mockito.inOrder; | ||
|
||
public class AdminCommandSectionTest | ||
{ | ||
@Mock | ||
private Consumer<String> out; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
MockitoAnnotations.initMocks( this ); | ||
} | ||
|
||
@Test | ||
public void shouldPrintUsageForAllCommandsAlphabetically() | ||
{ | ||
AdminCommandSection generalSection = AdminCommandSection.general(); | ||
|
||
List<AdminCommand.Provider> providers = asList( | ||
new StubProvider( "restore", "Restore", generalSection ), | ||
new StubProvider( "bam", "A summary", generalSection ), | ||
new StubProvider( "zzzz-last-one", "Another summary", generalSection ) ); | ||
generalSection.printAllCommandsUnderSection( out, providers ); | ||
|
||
InOrder ordered = inOrder( out ); | ||
ordered.verify( out ).accept( "General" ); | ||
ordered.verify( out ).accept( " bam" ); | ||
ordered.verify( out ).accept( " A summary" ); | ||
ordered.verify( out ).accept( " restore" ); | ||
ordered.verify( out ).accept( " Restore" ); | ||
ordered.verify( out ).accept( " zzzz-last-one" ); | ||
ordered.verify( out ).accept( " Another summary" ); | ||
ordered.verifyNoMoreInteractions(); | ||
} | ||
} |
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
Oops, something went wrong.