示例#1
0
文件: home.go 项目: clawio/clawio
func home(cmd *cobra.Command, args []string) {

	token, err := getToken()
	if err != nil {
		fmt.Println("Authentication required")
		os.Exit(1)
	}

	addr := os.Getenv("CLAWIO_CLI_META_ADDR")

	con, err := grpc.Dial(addr, grpc.WithInsecure())
	if err != nil {
		fmt.Println("Cannot connect to server " + addr)
		os.Exit(1)
	}

	defer con.Close()

	c := pb.NewMetaClient(con)

	in := &pb.HomeReq{}
	in.AccessToken = token

	ctx := context.Background()

	_, err = c.Home(ctx, in)
	if err != nil {
		fmt.Println("Cannot create homedir: " + err.Error())
		os.Exit(1)
	}

	fmt.Println("Home directory created")
}
示例#2
0
文件: stat.go 项目: clawio/clawio
func stat(cmd *cobra.Command, args []string) {

	if len(args) != 1 {
		fmt.Println("You have to provide a path")
		os.Exit(1)
	}

	token, err := getToken()
	if err != nil {
		fmt.Println("Authentication required")
		os.Exit(1)
	}

	addr := os.Getenv("CLAWIO_CLI_META_ADDR")

	con, err := grpc.Dial(addr, grpc.WithInsecure())
	if err != nil {
		fmt.Println("Cannot connect to server " + addr)
		os.Exit(1)
	}

	defer con.Close()

	c := pb.NewMetaClient(con)

	in := &pb.StatReq{}
	in.AccessToken = token
	in.Path = args[0]
	in.Children = childrenFlag

	ctx := context.Background()

	res, err := c.Stat(ctx, in)
	if err != nil {
		fmt.Println("Cannot stat resource: " + err.Error())
		os.Exit(1)
	}

	tabWriter := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
	defer tabWriter.Flush()

	fmt.Fprintln(tabWriter, "ID\tPath\tContainer\tSize\tModified\tPermissions\tETag\tMime\tChecksum")

	fmt.Fprintf(tabWriter, "%s\t%s\t%t\t%d\t%d\t%d\t%s\t%s\t%s\n",
		res.Id, res.Path, res.IsContainer, res.Size, res.Modified, res.Permissions, res.Etag, res.MimeType, res.Checksum)

	for _, child := range res.GetChildren() {
		fmt.Fprintf(tabWriter, "%s\t%s\t%t\t%d\t%d\t%d\t%s\t%s\t%s\n",
			child.Id, child.Path, child.IsContainer, child.Size, child.Modified, child.Permissions, child.Etag, child.MimeType, child.Checksum)
	}
}
示例#3
0
文件: cp.go 项目: clawio/clawio
func cp(cmd *cobra.Command, args []string) {

	if len(args) != 2 {
		fmt.Println("You have to provide src and dst paths")
		os.Exit(1)
	}

	token, err := getToken()
	if err != nil {
		fmt.Println("Authentication required")
		os.Exit(1)
	}

	addr := os.Getenv("CLAWIO_CLI_META_ADDR")

	con, err := grpc.Dial(addr, grpc.WithInsecure())
	if err != nil {
		fmt.Println("Cannot connect to server " + addr)
		os.Exit(1)
	}

	defer con.Close()

	c := pb.NewMetaClient(con)

	in := &pb.CpReq{}
	in.AccessToken = token
	in.Src = args[0]
	in.Dst = args[1]

	ctx := context.Background()

	_, err = c.Cp(ctx, in)
	if err != nil {
		fmt.Println("Cannot mv resource: " + err.Error())
		os.Exit(1)
	}

	fmt.Println("Copied " + args[0] + " to " + args[1])
}
示例#4
0
文件: rm.go 项目: clawio/clawio
func rm(cmd *cobra.Command, args []string) {

	if len(args) != 1 {
		fmt.Println("You have to provide a path")
		os.Exit(1)
	}

	token, err := getToken()
	if err != nil {
		fmt.Println("Authentication required")
		os.Exit(1)
	}

	addr := os.Getenv("CLAWIO_CLI_META_ADDR")

	con, err := grpc.Dial(addr, grpc.WithInsecure())
	if err != nil {
		fmt.Println("Cannot connect to server " + addr)
		os.Exit(1)
	}

	defer con.Close()

	c := pb.NewMetaClient(con)

	in := &pb.RmReq{}
	in.AccessToken = token
	in.Path = args[0]

	ctx := context.Background()

	_, err = c.Rm(ctx, in)
	if err != nil {
		fmt.Println("Cannot remove resource: " + err.Error())
		os.Exit(1)
	}

	fmt.Println("Removed " + args[0])
}