Move donut cmd into ./mc

This commit is contained in:
Harshavardhana
2015-03-23 14:15:16 -07:00
parent 760453fe32
commit deb889d2fb
5 changed files with 19 additions and 73 deletions
-1
View File
@@ -1 +0,0 @@
donut
-68
View File
@@ -1,68 +0,0 @@
package main
import (
"io"
"os"
"strings"
"net/url"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/donut"
)
func doDonutCp(c *cli.Context) {
var e donut.Donut
e = donut.NewDonutDriver("testdir")
switch len(c.Args()) {
case 2:
urlArg1, errArg1 := url.Parse(c.Args().Get(0))
if errArg1 != nil {
panic(errArg1)
}
urlArg2, errArg2 := url.Parse(c.Args().Get(1))
if errArg2 != nil {
panic(errArg2)
}
switch true {
case urlArg1.Scheme != "" && urlArg2.Scheme == "":
writer, err := os.Create(urlArg2.Path)
defer writer.Close()
if err != nil {
panic(err)
}
if urlArg1.Scheme == "donut" {
e.CreateBucket(urlArg1.Host)
reader, err := e.GetObject(urlArg1.Host, strings.TrimPrefix(urlArg1.Path, "/"))
if err != nil {
panic(err)
}
_, err = io.Copy(writer, reader)
if err != nil {
panic(err)
}
}
case urlArg1.Scheme == "" && urlArg2.Scheme != "":
st, stErr := os.Stat(urlArg1.Path)
if os.IsNotExist(stErr) {
panic(stErr)
}
if st.IsDir() {
panic("is a directory")
}
reader, err := os.OpenFile(urlArg1.Path, 2, os.ModeAppend)
defer reader.Close()
if err != nil {
panic(err)
}
if urlArg2.Scheme == "donut" {
e.CreateBucket(urlArg2.Host)
writer, err := e.GetObjectWriter(urlArg2.Host, strings.TrimPrefix(urlArg2.Path, "/"))
if err != nil {
panic(err)
}
io.Copy(writer, reader)
}
}
}
}
-39
View File
@@ -1,39 +0,0 @@
/*
* Minimalist 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 (
"net/url"
"github.com/codegangsta/cli"
"github.com/minio-io/mc/pkg/donut"
)
// doMakeBucketCmd creates a new bucket
func doMakeBucketCmd(c *cli.Context) {
urlArg1, err := url.Parse(c.Args().Get(0))
if err != nil {
panic(err)
}
var e donut.Donut
e = donut.NewDonutDriver("testdir")
err = e.CreateBucket(urlArg1.Path)
if err != nil {
panic(err)
}
}
-58
View File
@@ -1,58 +0,0 @@
/*
* Minimalist 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"
"os"
"os/user"
"github.com/codegangsta/cli"
)
func init() {
// Check for the environment early on and gracefuly report.
_, err := user.Current()
if err != nil {
log.Fatalf("mc: Unable to obtain user's home directory. \nError: %s\n", err)
}
}
var cp = cli.Command{
Name: "cp",
Action: doDonutCp,
}
var mb = cli.Command{
Name: "mb",
Action: doMakeBucketCmd,
}
var options = []cli.Command{
cp,
mb,
}
func main() {
app := cli.NewApp()
app.Usage = "Minio Client for S3 Compatible Object Storage"
app.Version = "0.1.0"
app.Commands = options
app.Author = "Minio.io"
app.EnableBashCompletion = true
app.Run(os.Args)
}