diff --git a/cmd/cli/main.go b/cmd/cli/main.go deleted file mode 100644 index bfe9db77..00000000 --- a/cmd/cli/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "log" - - "github.com/spf13/cobra" -) - -func main() { - cmd := &cobra.Command{ - Use: "athens", - Short: "The athens dependency manager", - Example: usage, - SilenceUsage: true, - } - - cmd.AddCommand(newUploadCmd()) - - if err := cmd.Execute(); err != nil { - log.Fatal(err) - } - -} diff --git a/cmd/cli/upload.go b/cmd/cli/upload.go deleted file mode 100644 index 87c2bfbb..00000000 --- a/cmd/cli/upload.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "path" - "path/filepath" - - parser "github.com/gomods/athens/pkg/gomod/file" - "github.com/gomods/athens/pkg/module" - "github.com/gomods/athens/pkg/payloads" - "github.com/spf13/afero" - "github.com/spf13/cobra" -) - -type uploadCmd struct { - moduleName string - version string - baseURL string -} - -func newUploadCmd() *cobra.Command { - uploadCmd := &uploadCmd{} - cmd := &cobra.Command{ - Use: "upload [directory]", - Short: "package up a directory and upload it to the athens server", - Args: cobra.ExactArgs(1), - RunE: upload(uploadCmd), - } - cmd.Flags().StringVarP(&uploadCmd.version, "version", "v", "v0.0.1", "The version of this module") - cmd.Flags().StringVarP(&uploadCmd.baseURL, "base-url", "u", "http://localhost:3000/admin/upload", "The Athens base url.") - return cmd -} - -func upload(c *uploadCmd) func(*cobra.Command, []string) error { - return func(cmd *cobra.Command, args []string) error { - fs := afero.NewOsFs() - dir := args[0] - - fullDirectory, err := filepath.Abs(dir) - if err != nil { - return fmt.Errorf("couldn't get full directory (%s)", err) - } - cmd.Printf("found directory %s", fullDirectory) - modFilePath := filepath.Join(fullDirectory, "go.mod") - modBytes, err := afero.ReadFile(fs, modFilePath) - if err != nil { - return fmt.Errorf("couldn't find go.mod file (%s)", err) - } - - gomodParser := parser.NewFileParser(fs, modFilePath) - c.moduleName, err = gomodParser.ModuleName() - if err != nil { - return fmt.Errorf("couldn't parse go.mod file (%s)", err) - } - - zipReader := module.MakeZip(fs, fullDirectory, c.moduleName, c.version) - - infoFilePath := filepath.Join(fullDirectory, c.version+".info") - infoBytes, err := afero.ReadFile(fs, infoFilePath) - if err != nil { - return fmt.Errorf("coudln't find .info file (%s)", err) - } - - u, err := url.Parse(c.baseURL) - if err != nil { - return fmt.Errorf("not a valid base url (%s)", err) - } - - u.Path = path.Join(u.Path, c.moduleName, c.version) - zipBytes, err := ioutil.ReadAll(zipReader) - if err != nil { - return err - } - postBody := &payloads.Upload{ - Module: modBytes, - Zip: zipBytes, - Info: infoBytes, - } - buf := new(bytes.Buffer) - if err := json.NewEncoder(buf).Encode(postBody); err != nil { - return fmt.Errorf("error encoding json (%s)", err) - } - cmd.Printf("POSTing to %s", u) - resp, err := http.Post(u.String(), "application/json", buf) - if err != nil { - return fmt.Errorf("error uploading (%s)", err) - } else if resp.StatusCode != 200 { - return fmt.Errorf("upload failed because status code was %d", resp.StatusCode) - } - cmd.Println("Upload successful!") - return nil - } -} diff --git a/cmd/cli/usage.go b/cmd/cli/usage.go deleted file mode 100644 index ae4ac283..00000000 --- a/cmd/cli/usage.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -const usage = `athens