Remove unnecessary CLI options

This commit is contained in:
Harshavardhana
2015-02-09 22:55:39 -08:00
parent 3c5d6d4373
commit 417a99f973
13 changed files with 87 additions and 569 deletions
+17 -49
View File
@@ -12,13 +12,24 @@ mc - unified command line interface for Minio Object Storage compatible with Ama
### Commands
```
# mc --help
...
...
...
NAME:
mc - Unified command line interface for Minio Object Storage
USAGE:
mc [global options] command [command options] [arguments...]
VERSION:
0.1.0
AUTHOR:
Minio Community
COMMANDS:
s3
s3api
cp
ls
mb
sync
configure
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
@@ -26,49 +37,6 @@ GLOBAL OPTIONS:
--version, -v print the version
```
### Sub-Commands
```
# mc s3 --help
NAME:
mc s3 -
USAGE:
mc s3 command [command options] [arguments...]
COMMANDS:
cp
ls
mb
sync
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```
```
# mc s3api --help
NAME:
mc s3api -
USAGE:
mc s3api command [command options] [arguments...]
COMMANDS:
get-object
put-object
put-bucket
list-objects
list-buckets
configure
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```
## Contribute
[Contribute to mc](./CONTRIBUTING.md)
+1 -22
View File
@@ -25,32 +25,11 @@ import (
"github.com/minio-io/mc/pkg/s3"
)
var Options = []cli.Command{
{
Name: "s3",
Usage: "",
Subcommands: subS3Options,
},
{
Name: "s3api",
Usage: "",
Subcommands: subS3APIOptions,
},
}
var subS3Options = []cli.Command{
var options = []cli.Command{
Cp,
Ls,
Mb,
Sync,
}
var subS3APIOptions = []cli.Command{
GetObject,
PutObject,
PutBucket,
ListObjects,
ListBuckets,
Configure,
}
+1 -1
View File
@@ -22,7 +22,7 @@ func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error
return accessKey, secretKey, nil
}
func doS3Configure(c *cli.Context) {
func doConfigure(c *cli.Context) {
var err error
var jAuth []byte
var accessKey, secretKey string
+12 -44
View File
@@ -12,59 +12,27 @@ mc - unified command line interface for Minio Object Storage compatible with Ama
### Commands
```
# mc --help
...
...
...
COMMANDS:
s3
s3api
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```
### Sub-Commands
```
# mc s3 --help
NAME:
mc s3 -
mc - Unified command line interface for Minio Object Storage
USAGE:
mc s3 command [command options] [arguments...]
mc [global options] command [command options] [arguments...]
VERSION:
0.1.0
AUTHOR:
Minio Community
COMMANDS:
cp
ls
mb
sync
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```
```
# mc s3api --help
NAME:
mc s3api -
USAGE:
mc s3api command [command options] [arguments...]
COMMANDS:
get-object
put-object
put-bucket
list-objects
list-buckets
configure
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```
+1 -1
View File
@@ -27,7 +27,7 @@ func main() {
app.Name = "mc"
app.Usage = "Unified command line interface for Minio Object Storage"
app.Version = "0.1.0"
app.Commands = Options
app.Commands = options
app.Author = "Minio Community"
app.Run(os.Args)
}
-129
View File
@@ -1,129 +0,0 @@
/*
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"github.com/codegangsta/cli"
)
var GetObject = cli.Command{
Name: "get-object",
Usage: "",
Description: "Retrieves objects from Amazon S3.",
Action: doGetObject,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "bucket name",
},
cli.StringFlag{
Name: "key",
Value: "",
Usage: "path to Object",
},
},
}
var PutObject = cli.Command{
Name: "put-object",
Usage: "",
Description: "Adds an object to a bucket.",
Action: doPutObject,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "bucket name",
},
cli.StringFlag{
Name: "key",
Value: "",
Usage: "Object name",
},
cli.StringFlag{
Name: "body",
Value: "",
Usage: "Object blob",
},
},
}
var PutBucket = cli.Command{
Name: "put-bucket",
Usage: "",
Description: "Adds an object to a bucket.",
Action: doPutBucket,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "bucket name",
},
},
}
var ListObjects = cli.Command{
Name: "list-objects",
Usage: "",
Description: `Returns some or all (up to 1000) of the objects in a bucket.
You can use the request parameters as selection criteria to
return a subset of the objects in a bucket.`,
Action: doListObjects,
Flags: []cli.Flag{
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "Bucket name",
},
},
}
var ListBuckets = cli.Command{
Name: "list-buckets",
Usage: "",
Description: `Returns a list of all buckets owned by the authenticated
sender of the request.`,
Action: doListBuckets,
}
var Configure = cli.Command{
Name: "configure",
Usage: "",
Description: `Configure minio client configuration data. If your config
file does not exist (the default location is ~/.s3auth), it will be
automatically created for you. Note that the configure command only writes
values to the config file. It does not use any configuration values from
the environment variables.`,
Action: doS3Configure,
Flags: []cli.Flag{
cli.StringFlag{
Name: "accesskey",
Value: "",
Usage: "AWS access key id",
},
cli.StringFlag{
Name: "secretkey",
Value: "",
Usage: "AWS secret key id",
},
},
}
const (
AUTH = ".auth"
)
+28
View File
@@ -17,6 +17,8 @@
package main
import (
"bytes"
"crypto/md5"
"hash"
"io"
"log"
@@ -33,6 +35,32 @@ import (
// - <S3Path> <S3Bucket>
// - <LocalDir> <S3Bucket>
func getPutMetadata(reader io.Reader) (md5hash hash.Hash, bodyBuf io.Reader, size int64, err error) {
md5hash = md5.New()
var length int
var bodyBuffer bytes.Buffer
for err == nil {
byteBuffer := make([]byte, 1024*1024)
length, err = reader.Read(byteBuffer)
// While hash.Write() wouldn't mind a Nil byteBuffer
// It is necessary for us to verify this and break
if length == 0 {
break
}
byteBuffer = byteBuffer[0:length]
_, err = bodyBuffer.Write(byteBuffer)
if err != nil {
break
}
md5hash.Write(byteBuffer)
}
if err != io.EOF {
return nil, nil, 0, err
}
return md5hash, &bodyBuffer, int64(bodyBuffer.Len()), nil
}
func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
switch len(c.Args()) {
case 1:
+27
View File
@@ -48,6 +48,29 @@ var Sync = cli.Command{
Action: doFsSync,
}
var Configure = cli.Command{
Name: "configure",
Usage: "",
Description: `Configure minio client configuration data. If your config
file does not exist (the default location is ~/.s3auth), it will be
automatically created for you. Note that the configure command only writes
values to the config file. It does not use any configuration values from
the environment variables.`,
Action: doConfigure,
Flags: []cli.Flag{
cli.StringFlag{
Name: "accesskey",
Value: "",
Usage: "AWS access key id",
},
cli.StringFlag{
Name: "secretkey",
Value: "",
Usage: "AWS secret key id",
},
},
}
type fsOptions struct {
bucket string
body string
@@ -56,5 +79,9 @@ type fsOptions struct {
isput bool
}
const (
AUTH = ".auth"
)
func doFsSync(c *cli.Context) {
}
-68
View File
@@ -1,68 +0,0 @@
/*
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"io"
"log"
"os"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/s3"
)
func parseGetObjectInput(c *cli.Context) (bucket, key string, err error) {
bucket = c.String("bucket")
key = c.String("key")
if bucket == "" {
return "", "", bucketNameErr
}
if key == "" {
return "", "", objectNameErr
}
return bucket, key, nil
}
func doGetObject(c *cli.Context) {
var bucket, key string
var err error
var objectReader io.ReadCloser
var objectSize int64
var auth *s3.Auth
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
bucket, key, err = parseGetObjectInput(c)
if err != nil {
log.Fatal(err)
}
s3c := s3.NewS3Client(auth)
objectReader, objectSize, err = s3c.Get(bucket, key)
if err != nil {
log.Fatal(err)
}
_, err = io.CopyN(os.Stdout, objectReader, objectSize)
if err != nil {
log.Fatal(err)
}
}
-32
View File
@@ -1,32 +0,0 @@
package main
import (
"log"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/s3"
)
func dumpBuckets(v []*s3.Bucket) {
for _, b := range v {
log.Printf("Bucket :%#v", b)
}
}
func doListBuckets(c *cli.Context) {
var err error
var auth *s3.Auth
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
var buckets []*s3.Bucket
s3c := s3.NewS3Client(auth)
buckets, err = s3c.Buckets()
if err != nil {
log.Fatal(err)
}
dumpBuckets(buckets)
}
-60
View File
@@ -1,60 +0,0 @@
/*
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"log"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/s3"
)
func parseListObjectsInput(c *cli.Context) (bucket string, err error) {
bucket = c.String("bucket")
if bucket == "" {
return "", bucketNameErr
}
return bucket, nil
}
func doListObjects(c *cli.Context) {
var err error
var auth *s3.Auth
var bucket string
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
bucket, err = parseListObjectsInput(c)
if err != nil {
log.Fatal(err)
}
var items []*s3.Item
s3c := s3.NewS3Client(auth)
// Gets 1000 maxkeys supported with GET Bucket API
items, err = s3c.GetBucket(bucket, "", s3.MAX_OBJECT_LIST)
if err != nil {
log.Fatal(err)
}
for _, item := range items {
log.Println(item)
}
}
-54
View File
@@ -1,54 +0,0 @@
/*
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"log"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/s3"
)
func parsePutBucketInput(c *cli.Context) (bucket string, err error) {
bucket = c.String("bucket")
if bucket == "" {
return "", bucketNameErr
}
return bucket, nil
}
func doPutBucket(c *cli.Context) {
var err error
var bucket string
var auth *s3.Auth
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
bucket, err = parsePutBucketInput(c)
if err != nil {
log.Fatal(err)
}
s3c := s3.NewS3Client(auth)
err = s3c.PutBucket(bucket)
if err != nil {
log.Fatal(err)
}
}
-109
View File
@@ -1,109 +0,0 @@
/*
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"bytes"
"crypto/md5"
"hash"
"io"
"log"
"os"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/s3"
)
func getPutMetadata(reader io.Reader) (md5hash hash.Hash, bodyBuf io.Reader, size int64, err error) {
md5hash = md5.New()
var length int
var bodyBuffer bytes.Buffer
for err == nil {
byteBuffer := make([]byte, 1024*1024)
length, err = reader.Read(byteBuffer)
// While hash.Write() wouldn't mind a Nil byteBuffer
// It is necessary for us to verify this and break
if length == 0 {
break
}
byteBuffer = byteBuffer[0:length]
_, err = bodyBuffer.Write(byteBuffer)
if err != nil {
break
}
md5hash.Write(byteBuffer)
}
if err != io.EOF {
return nil, nil, 0, err
}
return md5hash, &bodyBuffer, int64(bodyBuffer.Len()), nil
}
func parsePutObjectInput(c *cli.Context) (bucket, key, body string, err error) {
bucket = c.String("bucket")
key = c.String("key")
body = c.String("body")
if bucket == "" {
return "", "", "", bucketNameErr
}
if key == "" {
return "", "", "", objectNameErr
}
if body == "" {
return "", "", "", objectBlobErr
}
return bucket, key, body, nil
}
func doPutObject(c *cli.Context) {
var err error
var md5hash hash.Hash
var bucket, key, body string
var auth *s3.Auth
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
bucket, key, body, err = parsePutObjectInput(c)
if err != nil {
log.Fatal(err)
}
s3c := s3.NewS3Client(auth)
var bodyFile *os.File
bodyFile, err = os.Open(body)
if err != nil {
log.Fatal(err)
}
var bodyBuffer io.Reader
var size int64
md5hash, bodyBuffer, size, err = getPutMetadata(bodyFile)
if err != nil {
log.Fatal(err)
}
err = s3c.Put(bucket, key, md5hash, size, bodyBuffer)
if err != nil {
log.Fatal(err)
}
}