From 8ba6261e18b0f571a12ab503846d8175d1cbfd1f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 28 Apr 2015 12:50:44 -0700 Subject: [PATCH] Make getURL - getExpandedURL --- cmd-access.go | 2 +- cmd-cat.go | 2 +- cmd-cp.go | 2 +- cmd-ls.go | 2 +- cmd-mb.go | 2 +- cmd_test.go | 32 ++++++++++++++++---------------- url.go | 10 +++++----- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd-access.go b/cmd-access.go index 2604f4fc..1166b11a 100644 --- a/cmd-access.go +++ b/cmd-access.go @@ -39,7 +39,7 @@ func runAccessCmd(ctx *cli.Context) { } targetURLConfigMap := make(map[string]*hostConfig) - targetURLs, err := getURLs(ctx.Args(), config.Aliases) + targetURLs, err := getExpandedURLs(ctx.Args(), config.Aliases) if err != nil { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: diff --git a/cmd-cat.go b/cmd-cat.go index a4d29741..e7bdb28e 100644 --- a/cmd-cat.go +++ b/cmd-cat.go @@ -41,7 +41,7 @@ func runCatCmd(ctx *cli.Context) { } // Convert arguments to URLs: expand alias, fix format... - urls, err := getURLs(ctx.Args(), config.Aliases) + urls, err := getExpandedURLs(ctx.Args(), config.Aliases) if err != nil { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: diff --git a/cmd-cp.go b/cmd-cp.go index 10e4977c..625ca846 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -37,7 +37,7 @@ func runCopyCmd(ctx *cli.Context) { } // Convert arguments to URLs: expand alias, fix format... - urls, err := getURLs(ctx.Args(), config.Aliases) + urls, err := getExpandedURLs(ctx.Args(), config.Aliases) if err != nil { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: diff --git a/cmd-ls.go b/cmd-ls.go index b419aec5..7f50cdbc 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -39,7 +39,7 @@ func runListCmd(ctx *cli.Context) { } targetURLConfigMap := make(map[string]*hostConfig) for _, arg := range ctx.Args() { - targetURL, err := getURL(arg, config.Aliases) + targetURL, err := getExpandedURL(arg, config.Aliases) if err != nil { switch iodine.ToError(err).(type) { case errUnsupportedScheme: diff --git a/cmd-mb.go b/cmd-mb.go index 4a2a4a2c..a6900b51 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -38,7 +38,7 @@ func runMakeBucketCmd(ctx *cli.Context) { console.Fatalf("Unable to read config file [%s].\n", mustGetMcConfigPath()) } targetURLConfigMap := make(map[string]*hostConfig) - targetURLs, err := getURLs(ctx.Args(), config.Aliases) + targetURLs, err := getExpandedURLs(ctx.Args(), config.Aliases) if err != nil { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: diff --git a/cmd_test.go b/cmd_test.go index 72cf4c87..7e7df9fc 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -48,7 +48,7 @@ var _ = Suite(&CmdTestSuite{}) func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) { methods := &MockclientMethods{} - sourceURL, err := getURL("foo", nil) + sourceURL, err := getExpandedURL("foo", nil) c.Assert(err, IsNil) data := "Hello World" @@ -56,7 +56,7 @@ func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) { hexMd5 := hex.EncodeToString(md5Sum[:]) dataLength := int64(len(data)) - targetURL, err := getURL("bar", nil) + targetURL, err := getExpandedURL("bar", nil) c.Assert(err, IsNil) sourceReader, sourceWriter := io.Pipe() @@ -93,10 +93,10 @@ func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) { } func (s *CmdTestSuite) TestCopyRecursive(c *C) { - sourceURL, err := getURL("http://example.com/bucket1/", nil) + sourceURL, err := getExpandedURL("http://example.com/bucket1/", nil) c.Assert(err, IsNil) - targetURL, err := getURL("http://example.com/bucket2/", nil) + targetURL, err := getExpandedURL("http://example.com/bucket2/", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -192,10 +192,10 @@ func (c *failClose) Close() error { func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { methods := &MockclientMethods{} - sourceURL, err := getURL("foo", nil) + sourceURL, err := getExpandedURL("foo", nil) c.Assert(err, IsNil) - targetURL, err := getURL("bar", nil) + targetURL, err := getExpandedURL("bar", nil) c.Assert(err, IsNil) var nilReadCloser io.ReadCloser @@ -269,7 +269,7 @@ func (s *CmdTestSuite) TestCopyCmdFailures(c *C) { } func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) { - sourceURL, err := getURL("http://example.com/bucket1/", nil) + sourceURL, err := getExpandedURL("http://example.com/bucket1/", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -312,7 +312,7 @@ func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) { } func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) { - sourceURL, err := getURL("foo", nil) + sourceURL, err := getExpandedURL("foo", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -356,7 +356,7 @@ func (s *CmdTestSuite) TestLsCmdWithFilePath(c *C) { } func (s *CmdTestSuite) TestLsCmdListsBuckets(c *C) { - sourceURL, err := getURL("http://example.com", nil) + sourceURL, err := getExpandedURL("http://example.com", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -393,7 +393,7 @@ func (s *CmdTestSuite) TestLsCmdListsBuckets(c *C) { } func (s *CmdTestSuite) TestMbCmd(c *C) { - sourceURL, err := getURL("http://example.com/bucket1", nil) + sourceURL, err := getExpandedURL("http://example.com/bucket1", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -416,7 +416,7 @@ func (s *CmdTestSuite) TestMbCmd(c *C) { } func (s *CmdTestSuite) TestMbCmdFailures(c *C) { - sourceURL, err := getURL("http://example.com/bucket1", nil) + sourceURL, err := getExpandedURL("http://example.com/bucket1", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -461,7 +461,7 @@ func (s *CmdTestSuite) TestMbCmdFailures(c *C) { } func (s *CmdTestSuite) TestMbCmdOnFile(c *C) { - sourceURL, err := getURL("bucket1", nil) + sourceURL, err := getExpandedURL("bucket1", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -484,9 +484,9 @@ func (s *CmdTestSuite) TestMbCmdOnFile(c *C) { } func (s *CmdTestSuite) TestCatCmdObject(c *C) { - sourceURL, err := getURL("http://example.com/bucket1/object1", nil) + sourceURL, err := getExpandedURL("http://example.com/bucket1/object1", nil) c.Assert(err, IsNil) - targetURL, err := getURL("object1", nil) + targetURL, err := getExpandedURL("object1", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} @@ -537,9 +537,9 @@ func (s *CmdTestSuite) TestCatCmdObject(c *C) { } func (s *CmdTestSuite) TestCatCmdFile(c *C) { - sourceURL, err := getURL("object1", nil) + sourceURL, err := getExpandedURL("object1", nil) c.Assert(err, IsNil) - targetURL, err := getURL("object2", nil) + targetURL, err := getExpandedURL("object2", nil) c.Assert(err, IsNil) methods := &MockclientMethods{} diff --git a/url.go b/url.go index 3c0ba64f..a6ca55ba 100644 --- a/url.go +++ b/url.go @@ -35,8 +35,8 @@ func isURLRecursive(urlStr string) bool { return strings.HasSuffix(urlStr, recursiveSeparator) } -// getURL - extracts URL string from a single cmd-line argument -func getURL(arg string, aliases map[string]string) (urlStr string, err error) { +// getExpandedURL - extracts URL string from a single cmd-line argument +func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err error) { _, err = url.Parse(arg) if err != nil { // Not a valid URL. Return error @@ -56,10 +56,10 @@ func getURL(arg string, aliases map[string]string) (urlStr string, err error) { return urlStr, nil } -// getURLs - extracts multiple URL strings from a single cmd-line argument -func getURLs(args []string, aliases map[string]string) (urls []string, err error) { +// getExpandedURLs - extracts multiple URL strings from a single cmd-line argument +func getExpandedURLs(args []string, aliases map[string]string) (urls []string, err error) { for _, arg := range args { - u, err := getURL(arg, aliases) + u, err := getExpandedURL(arg, aliases) if err != nil { return nil, iodine.New(err, nil) }