You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cmd/sops/main.go
+39-22Lines changed: 39 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -722,8 +722,8 @@ func main() {
722
722
},
723
723
{
724
724
Name: "decrypt",
725
-
Usage: "decrypt a file, and output the results to stdout",
726
-
ArgsUsage: `file`,
725
+
Usage: "decrypt a file, and output the results to stdout. If no filename is provided, stdin will be used.",
726
+
ArgsUsage: `[file]`,
727
727
Flags: append([]cli.Flag{
728
728
cli.BoolFlag{
729
729
Name: "in-place, i",
@@ -751,7 +751,7 @@ func main() {
751
751
},
752
752
cli.StringFlag{
753
753
Name: "filename-override",
754
-
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
754
+
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type. Required when reading from stdin.",
755
755
},
756
756
cli.StringFlag{
757
757
Name: "decryption-order",
@@ -763,19 +763,24 @@ func main() {
763
763
ifc.Bool("verbose") {
764
764
logging.SetLevel(logrus.DebugLevel)
765
765
}
766
-
ifc.NArg() <1 {
767
-
returncommon.NewExitError("Error: no file specified", codes.NoFileSpecified)
766
+
ifc.NArg() ==0&&c.Bool("in-place") {
767
+
returncommon.NewExitError("Error: cannot use --in-place when reading from stdin", codes.ErrorConflictingParameters)
768
768
}
769
769
warnMoreThanOnePositionalArgument(c)
770
770
ifc.Bool("in-place") &&c.String("output") !="" {
771
771
returncommon.NewExitError("Error: cannot operate on both --output and --in-place", codes.ErrorConflictingParameters)
772
772
}
773
-
fileName, err:=filepath.Abs(c.Args()[0])
774
-
iferr!=nil {
775
-
returntoExitError(err)
776
-
}
777
-
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
778
-
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
773
+
readFromStdin:=c.NArg() ==0
774
+
varfileNamestring
775
+
varerrerror
776
+
if!readFromStdin {
777
+
fileName, err=filepath.Abs(c.Args()[0])
778
+
iferr!=nil {
779
+
returntoExitError(err)
780
+
}
781
+
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
782
+
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
783
+
}
779
784
}
780
785
fileNameOverride:=c.String("filename-override")
781
786
iffileNameOverride=="" {
@@ -806,6 +811,7 @@ func main() {
806
811
OutputStore: outputStore,
807
812
InputStore: inputStore,
808
813
InputPath: fileName,
814
+
ReadFromStdin: readFromStdin,
809
815
Cipher: aes.NewCipher(),
810
816
Extract: extract,
811
817
KeyServices: svcs,
@@ -847,8 +853,8 @@ func main() {
847
853
},
848
854
{
849
855
Name: "encrypt",
850
-
Usage: "encrypt a file, and output the results to stdout",
851
-
ArgsUsage: `file`,
856
+
Usage: "encrypt a file, and output the results to stdout. If no filename is provided, stdin will be used.",
857
+
ArgsUsage: `[file]`,
852
858
Flags: append([]cli.Flag{
853
859
cli.BoolFlag{
854
860
Name: "in-place, i",
@@ -926,26 +932,36 @@ func main() {
926
932
},
927
933
cli.StringFlag{
928
934
Name: "filename-override",
929
-
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
935
+
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type. Required when reading from stdin.",
930
936
},
931
937
}, keyserviceFlags...),
932
938
Action: func(c*cli.Context) error {
933
939
ifc.Bool("verbose") {
934
940
logging.SetLevel(logrus.DebugLevel)
935
941
}
936
-
ifc.NArg() <1 {
937
-
returncommon.NewExitError("Error: no file specified", codes.NoFileSpecified)
942
+
ifc.NArg() ==0 {
943
+
ifc.Bool("in-place") {
944
+
returncommon.NewExitError("Error: cannot use --in-place when reading from stdin", codes.ErrorConflictingParameters)
945
+
}
946
+
ifc.String("filename-override") =="" {
947
+
returncommon.NewExitError("Error: must specify --filename-override when reading from stdin", codes.ErrorConflictingParameters)
948
+
}
938
949
}
939
950
warnMoreThanOnePositionalArgument(c)
940
951
ifc.Bool("in-place") &&c.String("output") !="" {
941
952
returncommon.NewExitError("Error: cannot operate on both --output and --in-place", codes.ErrorConflictingParameters)
942
953
}
943
-
fileName, err:=filepath.Abs(c.Args()[0])
944
-
iferr!=nil {
945
-
returntoExitError(err)
946
-
}
947
-
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
948
-
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
954
+
readFromStdin:=c.NArg() ==0
955
+
varfileNamestring
956
+
varerrerror
957
+
if!readFromStdin {
958
+
fileName, err=filepath.Abs(c.Args()[0])
959
+
iferr!=nil {
960
+
returntoExitError(err)
961
+
}
962
+
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
963
+
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
0 commit comments