@@ -708,6 +708,10 @@ func main() {
708708 Name : "output" ,
709709 Usage : "Save the output after encryption or decryption to the file specified" ,
710710 },
711+ cli.StringFlag {
712+ Name : "filename-override" ,
713+ Usage : "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type" ,
714+ },
711715 }, keyserviceFlags ... )
712716
713717 app .Action = func (c * cli.Context ) error {
@@ -733,12 +737,16 @@ func main() {
733737 return common .NewExitError ("Error: cannot operate on non-existent file" , codes .NoFileSpecified )
734738 }
735739 }
740+ fileNameOverride := c .String ("filename-override" )
741+ if fileNameOverride == "" {
742+ fileNameOverride = fileName
743+ }
736744
737745 unencryptedSuffix := c .String ("unencrypted-suffix" )
738746 encryptedSuffix := c .String ("encrypted-suffix" )
739747 encryptedRegex := c .String ("encrypted-regex" )
740748 unencryptedRegex := c .String ("unencrypted-regex" )
741- conf , err := loadConfig (c , fileName , nil )
749+ conf , err := loadConfig (c , fileNameOverride , nil )
742750 if err != nil {
743751 return toExitError (err )
744752 }
@@ -781,19 +789,19 @@ func main() {
781789 unencryptedSuffix = sops .DefaultUnencryptedSuffix
782790 }
783791
784- inputStore := inputStore (c , fileName )
785- outputStore := outputStore (c , fileName )
792+ inputStore := inputStore (c , fileNameOverride )
793+ outputStore := outputStore (c , fileNameOverride )
786794 svcs := keyservices (c )
787795
788796 var output []byte
789797 if c .Bool ("encrypt" ) {
790798 var groups []sops.KeyGroup
791- groups , err = keyGroups (c , fileName )
799+ groups , err = keyGroups (c , fileNameOverride )
792800 if err != nil {
793801 return toExitError (err )
794802 }
795803 var threshold int
796- threshold , err = shamirThreshold (c , fileName )
804+ threshold , err = shamirThreshold (c , fileNameOverride )
797805 if err != nil {
798806 return toExitError (err )
799807 }
@@ -948,12 +956,12 @@ func main() {
948956 } else {
949957 // File doesn't exist, edit the example file instead
950958 var groups []sops.KeyGroup
951- groups , err = keyGroups (c , fileName )
959+ groups , err = keyGroups (c , fileNameOverride )
952960 if err != nil {
953961 return toExitError (err )
954962 }
955963 var threshold int
956- threshold , err = shamirThreshold (c , fileName )
964+ threshold , err = shamirThreshold (c , fileNameOverride )
957965 if err != nil {
958966 return toExitError (err )
959967 }
0 commit comments