Skip to content

Commit

Permalink
Added --version argument to neo4j-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Mar 28, 2017
1 parent 2840f66 commit d8f2b5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.neo4j.helpers.Args;

import static java.lang.String.format;
import static org.neo4j.commandline.Util.neo4jVersion;

public class AdminTool
{
Expand Down Expand Up @@ -75,6 +76,14 @@ public void execute( Path homeDir, Path configDir, String... args )
badUsage( "you must provide a command" );
return;
}

if ( Args.parse( args ).has( "version") )
{
outsideWorld.stdOutLine( "neo4j-admin " + neo4jVersion() );
success();
return;
}

String name = args[0];
String[] commandArgs = Arrays.copyOfRange( args, 1, args.length );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.mockito.Mockito.when;
import static org.neo4j.commandline.admin.AdminTool.STATUS_ERROR;
import static org.neo4j.commandline.admin.AdminTool.STATUS_SUCCESS;
import static org.neo4j.commandline.Util.neo4jVersion;

public class AdminToolTest
{
Expand Down Expand Up @@ -258,6 +259,34 @@ public void helpArgumentShouldAlwaysPrintHelp() throws CommandFailed, IncorrectU
verify( outsideWorld ).exit( STATUS_ERROR );
}

@Test
public void versionArgumentPrintsVersion() throws CommandFailed, IncorrectUsage
{
AdminCommand command = mock( AdminCommand.class );
OutsideWorld outsideWorld = mock( OutsideWorld.class );

new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false )
.execute( null, null, "--version" );

verifyNoMoreInteractions( command );
verify( outsideWorld ).stdOutLine( "neo4j-admin " + neo4jVersion() );
verify( outsideWorld ).exit( STATUS_SUCCESS );
}

@Test
public void versionArgumentPrintsVersionEvenWithCommand() throws CommandFailed, IncorrectUsage
{
AdminCommand command = mock( AdminCommand.class );
OutsideWorld outsideWorld = mock( OutsideWorld.class );

new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false )
.execute( null, null, "command", "--version" );

verifyNoMoreInteractions( command );
verify( outsideWorld ).stdOutLine( "neo4j-admin " + neo4jVersion() );
verify( outsideWorld ).exit( STATUS_SUCCESS );
}

private CannedLocator cannedCommand( final String name, AdminCommand command )
{
return new CannedLocator( new AdminCommand.Provider( name )
Expand Down

0 comments on commit d8f2b5e

Please sign in to comment.