func (b *CmdWriter) Variable(variable common.BuildVariable) { if variable.File { variableFile := b.Absolute(path.Join(b.TemporaryPath, variable.Key)) variableFile = helpers.ToBackslash(variableFile) b.Line(fmt.Sprintf("md %q 2>NUL 1>NUL", batchEscape(helpers.ToBackslash(b.TemporaryPath)))) b.Line(fmt.Sprintf("echo %s > %s", batchEscapeVariable(variable.Value), batchEscape(variableFile))) b.Line("SET " + batchEscapeVariable(variable.Key) + "=" + batchEscape(variableFile)) } else { b.Line("SET " + batchEscapeVariable(variable.Key) + "=" + batchEscapeVariable(variable.Value)) } }
func (b *PsWriter) Variable(variable common.BuildVariable) { if variable.File { variableFile := b.Absolute(path.Join(b.TemporaryPath, variable.Key)) variableFile = helpers.ToBackslash(variableFile) b.Line(fmt.Sprintf("md %s -Force | out-null", psQuote(helpers.ToBackslash(b.TemporaryPath)))) b.Line(fmt.Sprintf("Set-Content %s -Value %s -Encoding UTF8 -Force", psQuote(variableFile), psQuoteVariable(variable.Value))) b.Line("$" + variable.Key + "=" + psQuote(variableFile)) } else { b.Line("$" + variable.Key + "=" + psQuoteVariable(variable.Value)) } b.Line("$env:" + variable.Key + "=$" + variable.Key) }
func (b *PsWriter) RmFile(path string) { path = psQuote(helpers.ToBackslash(path)) b.Line("if( (Get-Command -Name Remove-Item2 -Module NTFSSecurity -ErrorAction SilentlyContinue) -and (Test-Path " + path + " -PathType Leaf) ) {") b.Indent() b.Line("Remove-Item2 -Force " + path) b.Unindent() b.Line("} elseif(Test-Path " + path + ") {") b.Indent() b.Line("Remove-Item -Force " + path) b.Unindent() b.Line("}") b.Line("") }
func (b *PsWriter) IfFile(path string) { b.Line("if(Test-Path " + psQuote(helpers.ToBackslash(path)) + " -PathType Leaf) {") b.Indent() }
func (b *PsWriter) IfDirectory(path string) { b.Line("if(Test-Path " + psQuote(helpers.ToBackslash(path)) + " -PathType Container) {") b.Indent() }
func (b *PsWriter) Cd(path string) { b.Line("cd " + psQuote(helpers.ToBackslash(path))) b.checkErrorLevel() }
func (b *CmdWriter) IfDirectory(path string) { b.Line("IF EXIST " + batchQuote(helpers.ToBackslash(path)) + " (") b.Indent() }
func (b *CmdWriter) RmFile(path string) { b.Line("rd /s /q " + batchQuote(helpers.ToBackslash(path)) + " 2>NUL 1>NUL") }
func (b *CmdWriter) Cd(path string) { b.Line("cd /D " + batchQuote(helpers.ToBackslash(path))) b.checkErrorLevel() }