@@ -769,6 +769,10 @@ func main() {
769769 Name : "output" ,
770770 Usage : "Save the output after encryption or decryption to the file specified" ,
771771 },
772+ cli.StringFlag {
773+ Name : "filename-override" ,
774+ Usage : "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type" ,
775+ },
772776 }, keyserviceFlags ... )
773777
774778 app .Action = func (c * cli.Context ) error {
@@ -795,13 +799,17 @@ func main() {
795799 return common .NewExitError ("Error: cannot operate on non-existent file" , codes .NoFileSpecified )
796800 }
797801 }
802+ fileNameOverride := c .String ("filename-override" )
803+ if fileNameOverride == "" {
804+ fileNameOverride = fileName
805+ }
798806
799807 unencryptedSuffix := c .String ("unencrypted-suffix" )
800808 encryptedSuffix := c .String ("encrypted-suffix" )
801809 encryptedRegex := c .String ("encrypted-regex" )
802810 unencryptedRegex := c .String ("unencrypted-regex" )
803811 macOnlyEncrypted := c .Bool ("mac-only-encrypted" )
804- conf , err := loadConfig (c , fileName , nil )
812+ conf , err := loadConfig (c , fileNameOverride , nil )
805813 if err != nil {
806814 return toExitError (err )
807815 }
@@ -847,19 +855,19 @@ func main() {
847855 unencryptedSuffix = sops .DefaultUnencryptedSuffix
848856 }
849857
850- inputStore := inputStore (c , fileName )
851- outputStore := outputStore (c , fileName )
858+ inputStore := inputStore (c , fileNameOverride )
859+ outputStore := outputStore (c , fileNameOverride )
852860 svcs := keyservices (c )
853861
854862 var output []byte
855863 if c .Bool ("encrypt" ) {
856864 var groups []sops.KeyGroup
857- groups , err = keyGroups (c , fileName )
865+ groups , err = keyGroups (c , fileNameOverride )
858866 if err != nil {
859867 return toExitError (err )
860868 }
861869 var threshold int
862- threshold , err = shamirThreshold (c , fileName )
870+ threshold , err = shamirThreshold (c , fileNameOverride )
863871 if err != nil {
864872 return toExitError (err )
865873 }
@@ -1015,12 +1023,12 @@ func main() {
10151023 } else {
10161024 // File doesn't exist, edit the example file instead
10171025 var groups []sops.KeyGroup
1018- groups , err = keyGroups (c , fileName )
1026+ groups , err = keyGroups (c , fileNameOverride )
10191027 if err != nil {
10201028 return toExitError (err )
10211029 }
10221030 var threshold int
1023- threshold , err = shamirThreshold (c , fileName )
1031+ threshold , err = shamirThreshold (c , fileNameOverride )
10241032 if err != nil {
10251033 return toExitError (err )
10261034 }
0 commit comments