99 "path"
1010 "strings"
1111
12- "github.com/kitech/qt.go/qtrt"
1312 "github.com/kitech/qt.go/toolutil"
1413)
1514
@@ -32,11 +31,11 @@ func main() {
3231 log .SetFlags (log .Flags () | log .Lshortfile )
3332 file = os .Args [1 ]
3433 filep = path .Base (file )[0 :strings .LastIndex (path .Base (file ), "." )]
35- filep = qtrt . IfElseStr (path .Dir (file ) == "" , filep , path .Dir (file )+ "/" + filep )
34+ filep = IfElseStr (path .Dir (file ) == "" , filep , path .Dir (file )+ "/" + filep )
3635 log .Println (file , filep )
3736
3837 scc , err := toolutil .RunCmdOut ("rcc" , file )
39- qtrt . ErrPrint (err , "rcc" , file )
38+ ErrPrint (err , "rcc" , file )
4039 if err != nil {
4140 os .Exit (1 )
4241 }
@@ -106,8 +105,11 @@ func main() {
106105}
107106
108107func transformMember (line string ) {
108+
109109 home := os .Getenv ("HOME" )
110- line = strings .Replace (line , home , "/home/me" , - 1 )
110+ if home != "" {
111+ line = strings .Replace (line , home , "/home/me" , - 1 )
112+ }
111113 cp .APf ("body" , line )
112114}
113115
@@ -145,15 +147,49 @@ func saveCode() {
145147 code += cp .ExportAll ()
146148 savefile := fmt .Sprintf ("%s_rc.go" , filep )
147149 err := ioutil .WriteFile (savefile , []byte (code ), mod )
148- qtrt . ErrPrint (err , savefile )
150+ ErrPrint (err , savefile )
149151
150152 // gofmt the code
151153 gofmtPath , err := exec .LookPath ("gofmt" )
152- qtrt . ErrPrint (err )
154+ ErrPrint (err )
153155 cmd := exec .Command (gofmtPath , "-w" , savefile )
154156 err = cmd .Run ()
155- qtrt . ErrPrint (err , cmd )
157+ ErrPrint (err , cmd )
156158}
157159
158160func colon2uline (s string ) string { return strings .Replace (s , ":" , "_" , - 1 ) }
159161func untitle (s string ) string { return strings .ToLower (s [0 :1 ]) + s [1 :] }
162+
163+ ///
164+ func printq (v interface {}, args ... interface {}) string {
165+ msg := fmt .Sprintf ("%+v" , v )
166+ for _ , arg := range args {
167+ msg += fmt .Sprintf (" %+v" , arg )
168+ }
169+ return msg
170+ }
171+
172+ func ErrPrint (err error , args ... interface {}) error {
173+ if err != nil {
174+ log .Output (2 , printq (err , args ... ))
175+ }
176+ return err
177+ }
178+
179+ // TODO 要是侯选可以惰性求值就好了,否则在只能一个求值的场景则会有问题
180+ // 简单的三元去处模拟函数
181+ func IfElse (q bool , tv interface {}, fv interface {}) interface {} {
182+ if q == true {
183+ return tv
184+ } else {
185+ return fv
186+ }
187+ }
188+
189+ func IfElseInt (q bool , tv int , fv int ) int {
190+ return IfElse (q , tv , fv ).(int )
191+ }
192+
193+ func IfElseStr (q bool , tv string , fv string ) string {
194+ return IfElse (q , tv , fv ).(string )
195+ }
0 commit comments