@@ -28,6 +28,8 @@ func NewInstallCmd() (cmd *cobra.Command) {
28
28
//flags.StringVarP(&opt.Mode, "mode", "m", "package",
29
29
// "If you want to install it via platform package manager")
30
30
flags .BoolVarP (& opt .ShowProgress , "show-progress" , "" , true , "If show the progress of download" )
31
+ flags .BoolVarP (& opt .Fetch , "fetch" , "" , true ,
32
+ "If fetch the latest config from https://github.com/LinuxSuRen/hd-home" )
31
33
flags .IntVarP (& opt .Thread , "thread" , "t" , 4 ,
32
34
`Download file with multi-threads. It only works when its value is bigger than 1` )
33
35
flags .BoolVarP (& opt .KeepPart , "keep-part" , "" , false ,
@@ -44,9 +46,11 @@ type installOption struct {
44
46
}
45
47
46
48
func (o * installOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
47
- if err = o .fetchHomeConfig (); err != nil {
48
- // this is not a fatal, don't block the process
49
- cmd .Printf ("Failed with fetching home config: %v\n " , err )
49
+ if o .Fetch {
50
+ if err = o .fetchHomeConfig (); err != nil {
51
+ err = fmt .Errorf ("failed with fetching home config: %v" , err )
52
+ return
53
+ }
50
54
}
51
55
err = o .downloadOption .preRunE (cmd , args )
52
56
return
@@ -153,8 +157,11 @@ func (o *installOption) extractFiles(tarFile, targetName string) (err error) {
153
157
return
154
158
}
155
159
156
- func execCommand (name string , arg ... string ) (err error ) {
160
+ func execCommandInDir (name , dir string , arg ... string ) (err error ) {
157
161
command := exec .Command (name , arg ... )
162
+ if dir != "" {
163
+ command .Dir = dir
164
+ }
158
165
159
166
//var stdout []byte
160
167
//var errStdout error
@@ -183,6 +190,10 @@ func execCommand(name string, arg ...string) (err error) {
183
190
return
184
191
}
185
192
193
+ func execCommand (name string , arg ... string ) (err error ) {
194
+ return execCommandInDir (name , "" , arg ... )
195
+ }
196
+
186
197
func copyAndCapture (w io.Writer , r io.Reader ) ([]byte , error ) {
187
198
var out []byte
188
199
buf := make ([]byte , 1024 , 1024 )
0 commit comments