--[[ $Id: //depot/p19.1/p4-test/server/extensions/examples/spec_pretty_printer/main.lua#5 $ $DateTime: 2019/04/30 10:51:56 $ $Author: jgibson $ $Change: 1796570 $ ]]-- 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