@@ -20,31 +20,65 @@ class WhiskInstaller {
2020
2121 let consoleIO = ConsoleIO ( )
2222 var projectPath : String !
23+ var argumentTarget : String ?
2324
2425 init ( ) {
2526 projectPath = getCurrentDirectory ( )
2627 }
2728
2829 func staticMode( ) {
29- let argCount = CommandLine . argc
30+ let argCount = Int ( CommandLine . argc)
3031 let argument = CommandLine . arguments [ 1 ]
32+
33+ var i = 1
34+ var isBuild = true
3135
32- if argCount > 2 {
33- projectPath = NSString ( string: CommandLine . arguments [ 2 ] ) . expandingTildeInPath as String
34- }
3536
36- var offset = 0
37- if argument. hasPrefix ( " -- " ) {
38- offset = 2
39- } else if argument. characters. first == " - " {
40- offset = 1
37+ while ( i < argCount) {
38+ let arg = CommandLine . arguments [ i]
39+
40+ var offset = 0
41+ if arg. hasPrefix ( " -- " ) {
42+ offset = 2
43+ } else if arg. characters. first == " - " {
44+ offset = 1
45+ }
46+
47+ let skipDashIndex = arg. index ( argument. startIndex, offsetBy: offset)
48+ let ( option, _) = consoleIO. getOption ( arg. substring ( from: skipDashIndex) )
49+
50+ switch option {
51+ case . Build:
52+ isBuild = true
53+ i = i + 1
54+ print ( " Got build " )
55+ case . Delete:
56+ isBuild = false
57+ i = i + 1
58+ print ( " Got delete " )
59+ case . Path:
60+ projectPath = CommandLine . arguments [ i+ 1 ]
61+ i = i + 2
62+ print ( " Got path \( projectPath) " )
63+ case . Target:
64+ argumentTarget = CommandLine . arguments [ i+ 1 ]
65+ i = i + 2
66+ print ( " Got target \( argumentTarget) " )
67+ case . Version:
68+ ConsoleIO . printVersion ( )
69+ i = i + 1
70+ case . Help:
71+ ConsoleIO . printUsage ( )
72+ i = i + 1
73+ case . Undefined:
74+ ConsoleIO . printUsage ( )
75+ i = i + 1
76+
77+ }
4178 }
4279
43- let skipDashIndex = argument. index ( argument. startIndex, offsetBy: offset)
44- let ( option, _) = consoleIO. getOption ( argument. substring ( from: skipDashIndex) )
45-
46- switch option {
47- case . Build:
80+ if isBuild == true {
81+
4882 do {
4983 if let pm = try setupProjectManager ( ) {
5084 try pm. deployProject ( )
@@ -54,7 +88,7 @@ class WhiskInstaller {
5488 } catch {
5589 print ( " Error installing OpenWhisk project \( error) " )
5690 }
57- case . Delete :
91+ } else {
5892 do {
5993 if let pm = try setupProjectManager ( ) {
6094 try pm. deleteProject ( )
@@ -64,13 +98,8 @@ class WhiskInstaller {
6498 } catch {
6599 print ( " Error installing OpenWhisk project \( error) " )
66100 }
67- case . Version:
68- ConsoleIO . printVersion ( )
69- case . Help:
70- ConsoleIO . printUsage ( )
71- case . Undefined:
72- ConsoleIO . printUsage ( )
73101 }
102+
74103 }
75104
76105 func getCurrentDirectory( ) -> String {
@@ -97,9 +126,13 @@ class WhiskInstaller {
97126 }
98127 }
99128
129+ if namespace == nil {
130+ namespace = " _ "
131+ }
132+
100133 if let tokens = tokens, let namespace = namespace {
101134 let credentials = WhiskCredentials ( accessKey: tokens [ 0 ] , accessToken: tokens [ 1 ] )
102- return ProjectManager ( path: projectPath!, credentials: credentials, namespace: namespace)
135+ return ProjectManager ( path: projectPath!, credentials: credentials, namespace: namespace, target : argumentTarget )
103136 }
104137 } catch {
105138 print ( " Error reading ~/.wskprops " )
0 commit comments