cmd

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Add file or folder to server",
	Long:  `Add file or folder to server`,
	Run: func(cmd *cobra.Command, args []string) {
		absFileNamePath, _ := filepath.Abs(fileNameParam)

		resp, _ := http.PostForm("http://localhost:7890/add", url.Values{"path": {absFileNamePath}})
		defer resp.Body.Close()
		body, _ := ioutil.ReadAll(resp.Body)

		res := api.AddResponse{}
		json.Unmarshal([]byte(body), &res)

		if res.Status {
			if len(res.ListIps) == 1 {
				copyClipboard(res.ListIps[0])
				return
			}

			fmt.Println("Choose option to copy to clipboard:")
			for i := 0; i < len(res.ListIps); i++ {
				fmt.Printf("%v) %s\n", i, res.ListIps[i])
			}

			var option int
			fmt.Scanf("%d", &option)
			copyClipboard(res.ListIps[option])
		} else {
			fmt.Printf("Error: %s\n", res.ErrorMessage)
		}
	},
}
View Source
var PsCmd = &cobra.Command{
	Use:   "ps",
	Short: "List files or folders from server",
	Long:  `List files or folders from server`,
	Run: func(cmd *cobra.Command, args []string) {
		resp, _ := http.Get("http://localhost:7890/ps")
		defer resp.Body.Close()
		body, _ := ioutil.ReadAll(resp.Body)

		res := []lib.Server{}
		json.Unmarshal([]byte(body), &res)

		lines := []string{
			"UUID | Folder | List Ips | CreatedAt",
		}

		for i := 0; i < len(res); i++ {
			line := fmt.Sprintf("%v|%s|%v|%v", res[i].UUID, res[i].Path, res[i].ListIps, res[i].CreatedAt)
			lines = append(lines, line)
		}

		result := columnize.SimpleFormat(lines)
		fmt.Println(result)
	},
}
View Source
var RmCmd = &cobra.Command{
	Use:   "rm",
	Short: "Remove file or folder from server",
	Long:  `Remove file or folder from server`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(removeServerUUID) == 0 {
			fmt.Println("Error: UUID empty!")
			return
		}

		url := fmt.Sprintf("http://localhost:7890/rm/%v", removeServerUUID)
		resp, _ := http.Get(url)
		defer resp.Body.Close()
		body, _ := ioutil.ReadAll(resp.Body)

		res := api.RmResponse{}
		json.Unmarshal([]byte(body), &res)

		if res.Status {
			fmt.Printf("Ok removed server with id = %s\n", removeServerUUID)
		} else {
			fmt.Printf("Error: %s\n", res.ErrorMessage)
		}
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "share",
	Short: "Share is a cli to share quickly a file with http protocol",
	Long:  `Share is a cli to share quickly a file with http protocol with go. Complete documentation is available at https://github.com/devcows/share`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("TODO use add, ps or rm")
	},
}
View Source
var ServerCmd = &cobra.Command{
	Use:   "server",
	Short: "Server APIREST",
	Long:  `Server APIREST`,
	Run: func(cmd *cobra.Command, args []string) {
		var err error

		if err = lib.InitSettings(lib.ConfigFile(), &settings); err != nil {
			fmt.Println(err)
			os.Exit(-1)
		}

		if err = lib.InitDB(settings); err != nil {
			fmt.Println(err)
			os.Exit(-1)
		}

		overwriteSettings()
		loadInitialServers()
		mainServer()
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL