@@ -21,7 +21,6 @@ import (
2121 "go.mozilla.org/sops/cmd/sops/common"
2222 "go.mozilla.org/sops/keyservice"
2323 "go.mozilla.org/sops/stores/json"
24- "gopkg.in/urfave/cli.v1"
2524)
2625
2726type editOpts struct {
@@ -91,7 +90,7 @@ func editExample(opts editExampleOpts) ([]byte, error) {
9190 var tree sops.Tree
9291 branch , err := opts .InputStore .Unmarshal (fileBytes )
9392 if err != nil {
94- return nil , cli .NewExitError (fmt .Sprintf ("Error unmarshalling file: %s" , err ), codes .CouldNotReadInputFile )
93+ return nil , common .NewExitError (fmt .Sprintf ("Error unmarshalling file: %s" , err ), codes .CouldNotReadInputFile )
9594 }
9695 tree .Branch = branch
9796 tree .Metadata = sops.Metadata {
@@ -104,7 +103,7 @@ func editExample(opts editExampleOpts) ([]byte, error) {
104103 // Generate a data key
105104 dataKey , errs := tree .GenerateDataKeyWithKeyServices (opts .KeyServices )
106105 if len (errs ) > 0 {
107- return nil , cli .NewExitError (fmt .Sprintf ("Error encrypting the data key with one or more master keys: %s" , errs ), codes .CouldNotRetrieveKey )
106+ return nil , common .NewExitError (fmt .Sprintf ("Error encrypting the data key with one or more master keys: %s" , errs ), codes .CouldNotRetrieveKey )
108107 }
109108
110109 return editTree (opts .editOpts , & tree , dataKey )
@@ -131,12 +130,12 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
131130 // Create temporary file for editing
132131 tmpdir , err := ioutil .TempDir ("" , "" )
133132 if err != nil {
134- return nil , cli .NewExitError (fmt .Sprintf ("Could not create temporary directory: %s" , err ), codes .CouldNotWriteOutputFile )
133+ return nil , common .NewExitError (fmt .Sprintf ("Could not create temporary directory: %s" , err ), codes .CouldNotWriteOutputFile )
135134 }
136135 defer os .RemoveAll (tmpdir )
137136 tmpfile , err := os .Create (path .Join (tmpdir , path .Base (opts .InputPath )))
138137 if err != nil {
139- return nil , cli .NewExitError (fmt .Sprintf ("Could not create temporary file: %s" , err ), codes .CouldNotWriteOutputFile )
138+ return nil , common .NewExitError (fmt .Sprintf ("Could not create temporary file: %s" , err ), codes .CouldNotWriteOutputFile )
140139 }
141140
142141 // Write to temporary file
@@ -147,17 +146,17 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
147146 out , err = opts .OutputStore .Marshal (tree .Branch )
148147 }
149148 if err != nil {
150- return nil , cli .NewExitError (fmt .Sprintf ("Could not marshal tree: %s" , err ), codes .ErrorDumpingTree )
149+ return nil , common .NewExitError (fmt .Sprintf ("Could not marshal tree: %s" , err ), codes .ErrorDumpingTree )
151150 }
152151 _ , err = tmpfile .Write (out )
153152 if err != nil {
154- return nil , cli .NewExitError (fmt .Sprintf ("Could not write output file: %s" , err ), codes .CouldNotWriteOutputFile )
153+ return nil , common .NewExitError (fmt .Sprintf ("Could not write output file: %s" , err ), codes .CouldNotWriteOutputFile )
155154 }
156155
157156 // Compute file hash to detect if the file has been edited
158157 origHash , err := hashFile (tmpfile .Name ())
159158 if err != nil {
160- return nil , cli .NewExitError (fmt .Sprintf ("Could not hash file: %s" , err ), codes .CouldNotReadInputFile )
159+ return nil , common .NewExitError (fmt .Sprintf ("Could not hash file: %s" , err ), codes .CouldNotReadInputFile )
161160 }
162161
163162 // Let the user edit the file
@@ -179,7 +178,7 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
179178 // Output the file
180179 encryptedFile , err := opts .OutputStore .MarshalWithMetadata (tree .Branch , tree .Metadata )
181180 if err != nil {
182- return nil , cli .NewExitError (fmt .Sprintf ("Could not marshal tree: %s" , err ), codes .ErrorDumpingTree )
181+ return nil , common .NewExitError (fmt .Sprintf ("Could not marshal tree: %s" , err ), codes .ErrorDumpingTree )
183182 }
184183 return encryptedFile , nil
185184}
@@ -188,18 +187,18 @@ func runEditorUntilOk(opts runEditorUntilOkOpts) error {
188187 for {
189188 err := runEditor (opts .TmpFile .Name ())
190189 if err != nil {
191- return cli .NewExitError (fmt .Sprintf ("Could not run editor: %s" , err ), codes .NoEditorFound )
190+ return common .NewExitError (fmt .Sprintf ("Could not run editor: %s" , err ), codes .NoEditorFound )
192191 }
193192 newHash , err := hashFile (opts .TmpFile .Name ())
194193 if err != nil {
195- return cli .NewExitError (fmt .Sprintf ("Could not hash file: %s" , err ), codes .CouldNotReadInputFile )
194+ return common .NewExitError (fmt .Sprintf ("Could not hash file: %s" , err ), codes .CouldNotReadInputFile )
196195 }
197196 if bytes .Equal (newHash , opts .OriginalHash ) {
198- return cli .NewExitError ("File has not changed, exiting." , codes .FileHasNotBeenModified )
197+ return common .NewExitError ("File has not changed, exiting." , codes .FileHasNotBeenModified )
199198 }
200199 edited , err := ioutil .ReadFile (opts .TmpFile .Name ())
201200 if err != nil {
202- return cli .NewExitError (fmt .Sprintf ("Could not read edited file: %s" , err ), codes .CouldNotReadInputFile )
201+ return common .NewExitError (fmt .Sprintf ("Could not read edited file: %s" , err ), codes .CouldNotReadInputFile )
203202 }
204203 newBranch , err := opts .InputStore .Unmarshal (edited )
205204 if err != nil {
@@ -228,7 +227,7 @@ func runEditorUntilOk(opts runEditorUntilOkOpts) error {
228227 opts .Tree .Branch = newBranch
229228 needVersionUpdated , err := AIsNewerThanB (version , opts .Tree .Metadata .Version )
230229 if err != nil {
231- return cli .NewExitError (fmt .Sprintf ("Failed to compare document version %q with program version %q: %v" , opts .Tree .Metadata .Version , version , err ), codes .FailedToCompareVersions )
230+ return common .NewExitError (fmt .Sprintf ("Failed to compare document version %q with program version %q: %v" , opts .Tree .Metadata .Version , version , err ), codes .FailedToCompareVersions )
232231 }
233232 if needVersionUpdated {
234233 opts .Tree .Metadata .Version = version
0 commit comments