Skip to content

Commit

Permalink
fix arguments parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Nov 11, 2020
1 parent 302eb63 commit d7bba81
Show file tree
Hide file tree
Showing 29 changed files with 417 additions and 49 deletions.
2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/azure/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/azure/gitversion/execute/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/azure/gitversion/setup/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/github/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/github/gitversion/execute/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/github/gitversion/setup/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/mock/gitversion/execute/bundle.js

Large diffs are not rendered by default.

59 changes: 55 additions & 4 deletions dist/mock/gitversion/setup/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/tools/gitreleasemanager/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export interface IGitReleaseManagerTool extends IDotnetTool {
}

@injectable()
export class GitReleaseManagerTool extends DotnetTool
export class GitReleaseManagerTool
extends DotnetTool
implements IGitReleaseManagerTool {
constructor(
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
Expand Down
67 changes: 64 additions & 3 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
workDir: string,
options: GitVersionSettings
): string[] {
const args = [workDir, '/output', 'json', '/output', 'buildserver']
let args = [workDir, '/output', 'json', '/output', 'buildserver']

const {
useConfigFile,
Expand Down Expand Up @@ -103,8 +103,7 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
}

if (additionalArguments) {
//args.push(additionalArguments)
Array.prototype.push.apply(args,additionalArguments.split(' '))
args = args.concat(this.argStringToArray(additionalArguments))
}
return args
}
Expand All @@ -120,6 +119,68 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
})
}

private argStringToArray(argString: string): string[] {
var args: string[] = []

var inQuotes = false
var escaped = false
var lastCharWasSpace = true
var arg = ''

var append = function (c: string) {
// we only escape double quotes.
if (escaped && c !== '"') {
arg += '\\'
}

arg += c
escaped = false
}

for (var i = 0; i < argString.length; i++) {
var c = argString.charAt(i)

if (c === ' ' && !inQuotes) {
if (!lastCharWasSpace) {
args.push(arg)
arg = ''
}
lastCharWasSpace = true
continue
} else {
lastCharWasSpace = false
}

if (c === '"') {
if (!escaped) {
inQuotes = !inQuotes
} else {
append(c)
}
continue
}

if (c === '\\' && escaped) {
append(c)
continue
}

if (c === '\\' && inQuotes) {
escaped = true
continue
}

append(c)
lastCharWasSpace = false
}

if (!lastCharWasSpace) {
args.push(arg.trim())
}

return args
}

private toCamelCase(input: string): string {
return input.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (
match,
Expand Down

0 comments on commit d7bba81

Please sign in to comment.