Compare commits
No commits in common. "099b0cd8497d0c0005f4ff6331508262c425160a" and "2e8c825fffbba8236e7ae3ad9607f89939a840dc" have entirely different histories.
099b0cd849
...
2e8c825fff
11
api/fs.go
11
api/fs.go
@ -19,12 +19,12 @@ func (c *Client) Rename(old, new string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Remove(paths ...string) error {
|
func (c *Client) Remove(path string) error {
|
||||||
_, err := c.request(types.Request{
|
_, err := c.request(types.Request{
|
||||||
Type: types.ReqTypeFS,
|
Type: types.ReqTypeFS,
|
||||||
Data: types.ReqDataFS{
|
Data: types.ReqDataFS{
|
||||||
Type: types.FSTypeDelete,
|
Type: types.FSTypeDelete,
|
||||||
Files: paths,
|
Files: []string{path},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,12 +33,12 @@ func (c *Client) Remove(paths ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Mkdir(paths ...string) error {
|
func (c *Client) Mkdir(path string) error {
|
||||||
_, err := c.request(types.Request{
|
_, err := c.request(types.Request{
|
||||||
Type: types.ReqTypeFS,
|
Type: types.ReqTypeFS,
|
||||||
Data: types.ReqDataFS{
|
Data: types.ReqDataFS{
|
||||||
Type: types.FSTypeMkdir,
|
Type: types.FSTypeMkdir,
|
||||||
Files: paths,
|
Files: []string{path},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,9 +84,8 @@ func (c *Client) WriteFile(path, data string) error {
|
|||||||
_, err := c.request(types.Request{
|
_, err := c.request(types.Request{
|
||||||
Type: types.ReqTypeFS,
|
Type: types.ReqTypeFS,
|
||||||
Data: types.ReqDataFS{
|
Data: types.ReqDataFS{
|
||||||
Type: types.FSTypeWrite,
|
Type: types.FSTypeRead,
|
||||||
Files: []string{path},
|
Files: []string{path},
|
||||||
Data: data,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"go.arsenm.dev/itd/cmd/itctl/root"
|
|
||||||
)
|
|
||||||
|
|
||||||
// filesystemCmd represents the get command
|
|
||||||
var filesystemCmd = &cobra.Command{
|
|
||||||
Use: "filesystem",
|
|
||||||
Aliases: []string{"fs"},
|
|
||||||
Short: "Perform filesystem operations on the PineTime",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
root.RootCmd.AddCommand(filesystemCmd)
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// listCmd represents the heart command
|
|
||||||
var listCmd = &cobra.Command{
|
|
||||||
Use: "list [path]",
|
|
||||||
Aliases: []string{"ls"},
|
|
||||||
Short: "List a directory",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
dirPath := "/"
|
|
||||||
if len(args) > 0 {
|
|
||||||
dirPath = args[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
listing, err := client.ReadDir(dirPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error getting directory listing")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, entry := range listing {
|
|
||||||
fmt.Println(entry)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(listCmd)
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// heartCmd represents the heart command
|
|
||||||
var mkdirCmd = &cobra.Command{
|
|
||||||
Use: "mkdir <path...>",
|
|
||||||
Short: "Create a new directory",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) < 1 {
|
|
||||||
cmd.Usage()
|
|
||||||
log.Fatal().Msg("Command mkdir requires one or more arguments")
|
|
||||||
}
|
|
||||||
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
err := client.Mkdir(args...)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error creating directory")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(mkdirCmd)
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// heartCmd represents the heart command
|
|
||||||
var moveCmd = &cobra.Command{
|
|
||||||
Use: "move <old> <new>",
|
|
||||||
Aliases: []string{"mv"},
|
|
||||||
Short: "Move a file or directory",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) != 2 {
|
|
||||||
cmd.Usage()
|
|
||||||
log.Fatal().Msg("Command move requires two arguments")
|
|
||||||
}
|
|
||||||
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
err := client.Rename(args[0], args[1])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error moving file or directory")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(moveCmd)
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// heartCmd represents the heart command
|
|
||||||
var readCmd = &cobra.Command{
|
|
||||||
Use: `read <remote path> <local path | "-">`,
|
|
||||||
Short: "Read a file from InfiniTime",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) != 2 {
|
|
||||||
cmd.Usage()
|
|
||||||
log.Fatal().Msg("Command read requires two arguments")
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
data, err := client.ReadFile(args[0])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error moving file or directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
var out *os.File
|
|
||||||
if args[1] == "-" {
|
|
||||||
out = os.Stdout
|
|
||||||
} else {
|
|
||||||
out, err = os.Create(args[1])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error opening local file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := out.WriteString(data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error writing to local file")
|
|
||||||
}
|
|
||||||
log.Info().Msgf("Read %d bytes in %s", n, time.Since(start))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(readCmd)
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// heartCmd represents the heart command
|
|
||||||
var removeCmd = &cobra.Command{
|
|
||||||
Use: "remove <path...>",
|
|
||||||
Aliases: []string{"rm"},
|
|
||||||
Short: "Create a new directory",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) < 1 {
|
|
||||||
cmd.Usage()
|
|
||||||
log.Fatal().Msg("Command mkdir requires one or more arguments")
|
|
||||||
}
|
|
||||||
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
err := client.Remove(args...)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error removing file or directory")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(removeCmd)
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* itd uses bluetooth low energy to communicate with InfiniTime devices
|
|
||||||
* Copyright (C) 2021 Arsen Musayelyan
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package filesystem
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"go.arsenm.dev/itd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// heartCmd represents the heart command
|
|
||||||
var writeCmd = &cobra.Command{
|
|
||||||
Use: `write <local path | "-"> <remote path>`,
|
|
||||||
Short: "Write a file to InfiniTime",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) != 2 {
|
|
||||||
cmd.Usage()
|
|
||||||
log.Fatal().Msg("Command write requires two arguments")
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
client := viper.Get("client").(*api.Client)
|
|
||||||
|
|
||||||
var in *os.File
|
|
||||||
if args[0] == "-" {
|
|
||||||
in = os.Stdin
|
|
||||||
} else {
|
|
||||||
fl, err := os.Open(args[0])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error opening local file")
|
|
||||||
}
|
|
||||||
in = fl
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := io.ReadAll(in)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error moving file or directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = client.WriteFile(args[1], string(data))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("Error writing to remote file")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info().Msgf("Wrote %d bytes in %s", len(data), time.Since(start))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
filesystemCmd.AddCommand(writeCmd)
|
|
||||||
}
|
|
@ -25,7 +25,6 @@ import (
|
|||||||
"go.arsenm.dev/itd/cmd/itctl/root"
|
"go.arsenm.dev/itd/cmd/itctl/root"
|
||||||
_ "go.arsenm.dev/itd/cmd/itctl/set"
|
_ "go.arsenm.dev/itd/cmd/itctl/set"
|
||||||
_ "go.arsenm.dev/itd/cmd/itctl/watch"
|
_ "go.arsenm.dev/itd/cmd/itctl/watch"
|
||||||
_ "go.arsenm.dev/itd/cmd/itctl/filesystem"
|
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user