--[[ $Id: //depot/main/p4-test/server/extensions/examples/spec_pretty_printer/main.lua#4 $ $DateTime: 2019/06/13 09:17:32 $ $Author: npoole $ $Change: 1816253 $ ]]-- package.path = Helix.Core.Server.GetArchDirFileName( "?.lua" ) local utils = require "ExtUtils" local sfmt = require "SpecFormatter" local initDone = false function init() if not initdone then initDone = 1 utils.init() sfmt.init( utils ) end end function GlobalConfigFields() return {} end function InstanceConfigFields() --formType = "the spec to format - e.g. branch/label/protect", return { stripHeaderComment = "Remove the comment from the form: true/false", formType = "The form type to format: branch/client/label/protect/triggers", users = "Space-separated list of which users get formatted specs" } end function InstanceConfigEvents() init() local validForms = { branch = 1, client = 1, label = 1, protect = 1, triggers = 1 } local form = utils.iCfgData[ "formType" ] if form == nil or validForms[ form ] == nil then print("form = '".. form .."'") if form == nil then print("nil form") end if validForms[ form ] == nil then print("validForms[ form ] == nil") end return false -- todo: This causes a bad_any_cast end return { ["form-out"] = form } end function FormOut() init() -- This Extension is only for the CLI since other programs may be sensitive -- to the formatting (e.g. P4V). if Helix.Core.Server.GetVar( "clientprog" ) ~= "p4" then return true end -- todo: look at the icfg list if Helix.Core.Server.GetVar( "user" ) == "nofmt" then return true end local icfg = Helix.Core.Server.GetInstanceConfigData() local ok, data = sfmt.Format( Helix.Core.Server.GetVar( "formtype" ), Helix.Core.Server.GetVar( "formfile" ), icfg[ keepComments ] ) if not ok then Helix.Core.Server.SetClientMsg( utils.msgHeader() .. data ) return false end return true end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 30809 | C. Thomas Tyler |
Code drop with newer versions of Extensions. Thanks to @jason_gibon. #review-30810 @jabson_gibson |
||
#1 | 30808 | C. Thomas Tyler |
Promoted from 2019.1/... to main/... |
||
//guest/perforce_software/extensions/2019.1/spec_pretty_printer/main.lua | |||||
#1 | 25601 | Jason Gibson |
Import example Extensions. p19.1@1797741 |