Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: vpython/application/flag.go

Issue 2937123003: [vpython] Fix flag parsing bug with "--". (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | vpython/application/flag_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package application 5 package application
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "strings" 9 "strings"
10 ) 10 )
(...skipping 15 matching lines...) Expand all
26 return 26 return
27 case len(args[0]) == 0 || args[0][0] != '-': 27 case len(args[0]) == 0 || args[0][0] != '-':
28 // If our first argument isn't a flag, then everything belongs t o 28 // If our first argument isn't a flag, then everything belongs t o
29 // "remainder", no processing necessary. 29 // "remainder", no processing necessary.
30 remainder = args 30 remainder = args
31 return 31 return
32 } 32 }
33 33
34 // Scan "args" for a "--" divider. We only process candidates to the lef t of 34 // Scan "args" for a "--" divider. We only process candidates to the lef t of
35 // the divider. 35 // the divider.
36 candidates := args 36 candidates := args
qyearsley 2017/06/15 20:12:54 One thing that isn't very clear to me when reading
37 for i, arg := range args { 37 for i, arg := range args {
38 if arg == "--" { 38 if arg == "--" {
39 candidates = args[:i] 39 candidates = args[:i]
40 break 40 break
41 } 41 }
42 } 42 }
43 if len(candidates) == 0 { 43 if len(candidates) == 0 {
44 remainder = args 44 remainder = args
45 return 45 return
46 } 46 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 if flagIsBool || single { 89 if flagIsBool || single {
90 return 1 90 return 1
91 } 91 }
92 return 2 92 return 2
93 } 93 }
94 94
95 for i := 0; i < len(candidates); { 95 for i := 0; i < len(candidates); {
96 consume := processOne(candidates[i:]) 96 consume := processOne(candidates[i:])
97 if consume == 0 { 97 if consume == 0 {
98 » » » fsArgs, remainder = args[:i], candidates[i:] 98 » » » fsArgs, remainder = args[:i], args[i:]
99 return 99 return
100 } 100 }
101 i += consume 101 i += consume
102 } 102 }
103 103
104 // Got to the end with no non-"fs" flags, so everything goes to fsArgs. 104 // Got to the end with no non-"fs" flags, so everything goes to fsArgs.
105 fsArgs, remainder = candidates, args[len(candidates):] 105 fsArgs, remainder = candidates, args[len(candidates):]
106 return 106 return
107 } 107 }
OLDNEW
« no previous file with comments | « no previous file | vpython/application/flag_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698