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
@@ -707,8 +707,8 @@ func main() {
707
707
},
708
708
{
709
709
Name: "decrypt",
710
-
Usage: "decrypt a file, and output the results to stdout",
711
-
ArgsUsage: `file`,
710
+
Usage: "decrypt a file, and output the results to stdout. If no filename is provided, stdin will be used.",
711
+
ArgsUsage: `[file]`,
712
712
Flags: append([]cli.Flag{
713
713
cli.BoolFlag{
714
714
Name: "in-place, i",
@@ -736,7 +736,7 @@ func main() {
736
736
},
737
737
cli.StringFlag{
738
738
Name: "filename-override",
739
-
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
739
+
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.",
740
740
},
741
741
cli.StringFlag{
742
742
Name: "decryption-order",
@@ -748,19 +748,24 @@ func main() {
748
748
ifc.Bool("verbose") {
749
749
logging.SetLevel(logrus.DebugLevel)
750
750
}
751
-
ifc.NArg() <1 {
752
-
returncommon.NewExitError("Error: no file specified", codes.NoFileSpecified)
751
+
ifc.NArg() ==0&&c.Bool("in-place") {
752
+
returncommon.NewExitError("Error: cannot use --in-place when reading from stdin", codes.ErrorConflictingParameters)
753
753
}
754
754
warnMoreThanOnePositionalArgument(c)
755
755
ifc.Bool("in-place") &&c.String("output") !="" {
756
756
returncommon.NewExitError("Error: cannot operate on both --output and --in-place", codes.ErrorConflictingParameters)
757
757
}
758
-
fileName, err:=filepath.Abs(c.Args()[0])
759
-
iferr!=nil {
760
-
returntoExitError(err)
761
-
}
762
-
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
763
-
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
758
+
readFromStdin:=c.NArg() ==0
759
+
varfileNamestring
760
+
varerrerror
761
+
if!readFromStdin {
762
+
fileName, err=filepath.Abs(c.Args()[0])
763
+
iferr!=nil {
764
+
returntoExitError(err)
765
+
}
766
+
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
767
+
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
768
+
}
764
769
}
765
770
fileNameOverride:=c.String("filename-override")
766
771
iffileNameOverride=="" {
@@ -791,6 +796,7 @@ func main() {
791
796
OutputStore: outputStore,
792
797
InputStore: inputStore,
793
798
InputPath: fileName,
799
+
ReadFromStdin: readFromStdin,
794
800
Cipher: aes.NewCipher(),
795
801
Extract: extract,
796
802
KeyServices: svcs,
@@ -832,8 +838,8 @@ func main() {
832
838
},
833
839
{
834
840
Name: "encrypt",
835
-
Usage: "encrypt a file, and output the results to stdout",
836
-
ArgsUsage: `file`,
841
+
Usage: "encrypt a file, and output the results to stdout. If no filename is provided, stdin will be used.",
842
+
ArgsUsage: `[file]`,
837
843
Flags: append([]cli.Flag{
838
844
cli.BoolFlag{
839
845
Name: "in-place, i",
@@ -911,26 +917,36 @@ func main() {
911
917
},
912
918
cli.StringFlag{
913
919
Name: "filename-override",
914
-
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
920
+
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.",
915
921
},
916
922
}, keyserviceFlags...),
917
923
Action: func(c*cli.Context) error {
918
924
ifc.Bool("verbose") {
919
925
logging.SetLevel(logrus.DebugLevel)
920
926
}
921
-
ifc.NArg() <1 {
922
-
returncommon.NewExitError("Error: no file specified", codes.NoFileSpecified)
927
+
ifc.NArg() ==0 {
928
+
ifc.Bool("in-place") {
929
+
returncommon.NewExitError("Error: cannot use --in-place when reading from stdin", codes.ErrorConflictingParameters)
930
+
}
931
+
ifc.String("filename-override") =="" {
932
+
returncommon.NewExitError("Error: must specify --filename-override when reading from stdin", codes.ErrorConflictingParameters)
933
+
}
923
934
}
924
935
warnMoreThanOnePositionalArgument(c)
925
936
ifc.Bool("in-place") &&c.String("output") !="" {
926
937
returncommon.NewExitError("Error: cannot operate on both --output and --in-place", codes.ErrorConflictingParameters)
927
938
}
928
-
fileName, err:=filepath.Abs(c.Args()[0])
929
-
iferr!=nil {
930
-
returntoExitError(err)
931
-
}
932
-
if_, err:=os.Stat(fileName); os.IsNotExist(err) {
933
-
returncommon.NewExitError(fmt.Sprintf("Error: cannot operate on non-existent file %q", fileName), codes.NoFileSpecified)
939
+
readFromStdin:=c.NArg() ==0
940
+
varfileNamestring
941
+
varerrerror
942
+
if!readFromStdin {
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)
0 commit comments