--[[ Example client-side loose Extension to implement a 'p4 bisect' command. Bisection in this context is the act of performing binary search on a codebase's history to discover the commit responsible for introducing a bug. NOTE: This example is only an outline of the actual command, but serves to illustrate how to create a new command with an Extension. ]]-- function table.contains( table, element ) for _, value in pairs( table ) do if value == element then return true end end return false end function preCommand() local func = Helix.Core.Client.GetVar( "func" ) local argc = Helix.Core.Client.GetVar( "argc" ) local argv = Helix.Core.Client.GetVar( "argv" ) if func ~= "bisect" then return Helix.Core.Client.Action.PASS end if argc == 0 then Helix.Core.Client.ClientMsg( "this is p4 bisect" ) end if table.contains( argv, "start" ) then Helix.Core.Client.ClientMsg( "bisect starting" ) end if table.contains( argv, "bad" ) then Helix.Core.Client.ClientMsg( "bisect bad" ) end if table.contains( argv, "good" ) then Helix.Core.Client.ClientMsg( "bisect good" ) end if table.contains( argv, "reset" ) then Helix.Core.Client.ClientMsg( "bisect reset" ) end if table.contains( argv, "zoop" ) then Helix.Core.Client.ClientError( "bisect bad argument" ) return Helix.Core.Client.Action.FAIL end -- There's no real 'p4 bisect', so we have to replace the command before -- the client actually sends it off to the server since the server will -- send us back an error saying it doesn't know what we're talking about. return Helix.Core.Client.Action.REPLACE end