Merge pull request #986 from harshavardhana/print-json
Print json output for share urls as well
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
@@ -160,3 +162,25 @@ func (s MirrorMessage) String() string {
|
||||
}
|
||||
return console.JSON(string(mirrorMessageBytes) + "\n")
|
||||
}
|
||||
|
||||
// ShareMessage container for share messages
|
||||
type ShareMessage struct {
|
||||
Version string `json:"version"`
|
||||
Expires time.Duration `json:"expires"`
|
||||
PresignedURL string `json:"presigned-url"`
|
||||
}
|
||||
|
||||
// String string printer for share message
|
||||
func (s ShareMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("Succesfully generated shared URL with expiry %s, please share: %s\n", s.Expires, s.PresignedURL)
|
||||
}
|
||||
s.Version = "1.0.0"
|
||||
shareMessageBytes, err := json.MarshalIndent(s, "", "\t")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// json encoding escapes ampersand into its unicode character which is not usable directly for share and fails with cloud storage.
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
|
||||
return console.JSON("%s\n", string(shareMessageBytes))
|
||||
}
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -114,7 +113,7 @@ func doShareCmd(targetURL string, recursive bool, expires time.Duration) *probe.
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
}
|
||||
console.PrintC(fmt.Sprintf("Succesfully generated shared URL with expiry %s, please copy: %s\n", expires, presignedURL))
|
||||
console.PrintC(ShareMessage{Expires: expires, PresignedURL: presignedURL})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user