Compare commits
7 Commits
3cfcdb7a01
...
v0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 4847eee540 | |||
| 19caa3ee83 | |||
| e523a024ec | |||
| 4a3dff646c | |||
| 986d2064a7 | |||
| 95cf5bfe6b | |||
| 0d70dd9b11 |
3
.gitm.toml
Normal file
3
.gitm.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[repos]
|
||||
origin = "ssh://git@192.168.100.62:2222/Arsen6331/itd.git"
|
||||
gitlab = "git@gitlab.com:moussaelianarsen/itd.git"
|
||||
4
Makefile
4
Makefile
@@ -4,8 +4,8 @@ SERVICE_PREFIX = $(DESTDIR)$(PREFIX)/lib/systemd/user
|
||||
CFG_PREFIX = $(DESTDIR)/etc
|
||||
|
||||
all:
|
||||
go build
|
||||
go build ./cmd/itctl
|
||||
go build $(GOFLAGS)
|
||||
go build ./cmd/itctl $(GOFLAGS)
|
||||
|
||||
install:
|
||||
install -Dm755 ./itd $(BIN_PREFIX)/itd
|
||||
|
||||
17
README.md
17
README.md
@@ -60,7 +60,7 @@ Use "itctl [command] --help" for more information about a command.
|
||||
|
||||
### Installation
|
||||
|
||||
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`.
|
||||
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`. The go compiler must be version 1.16 or newer for the `io/fs` module.
|
||||
|
||||
To install, run
|
||||
```shell
|
||||
@@ -69,6 +69,21 @@ make && sudo make install
|
||||
|
||||
---
|
||||
|
||||
### Starting
|
||||
|
||||
To start the daemon, run the following **without root**:
|
||||
|
||||
```shell
|
||||
systemctl --user start itd
|
||||
```
|
||||
|
||||
To autostart on login, run:
|
||||
```shell
|
||||
systemctl --user enable itd
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Cross compiling
|
||||
|
||||
To cross compile, simply set the go environment variables. For example, for PinePhone, use:
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/abiosoft/ishell"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,34 @@ import (
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "itctl",
|
||||
Short: "Control the itd daemon for InfiniTime smartwatches",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// Create new shell
|
||||
sh := ishell.New()
|
||||
sh.SetPrompt("itctl> ")
|
||||
|
||||
// For every command in cobra
|
||||
for _, subCmd := range cmd.Commands() {
|
||||
// Add top level command to ishell
|
||||
sh.AddCmd(&ishell.Cmd{
|
||||
Name: subCmd.Name(),
|
||||
Help: subCmd.Short,
|
||||
Aliases: subCmd.Aliases,
|
||||
LongHelp: subCmd.Long,
|
||||
Func: func(ctx *ishell.Context) {
|
||||
// Append name and arguments of command
|
||||
args := append([]string{ctx.Cmd.Name}, ctx.Args...)
|
||||
// Set root command arguments
|
||||
cmd.SetArgs(args)
|
||||
// Execute root command with new arguments
|
||||
cmd.Execute()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Start shell
|
||||
sh.Run()
|
||||
},
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
|
||||
@@ -36,9 +36,10 @@ var timeCmd = &cobra.Command{
|
||||
// Ensure required arguments
|
||||
if len(args) != 1 {
|
||||
cmd.Usage()
|
||||
log.Fatal().Msg("Command time requires one argument")
|
||||
log.Warn().Msg("Command time requires one argument")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Connect to itd UNIX socket
|
||||
conn, err := net.Dial("unix", SockPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -60,7 +60,8 @@ var upgradeCmd = &cobra.Command{
|
||||
}
|
||||
} else {
|
||||
cmd.Usage()
|
||||
log.Fatal().Msg("Upgrade command requires either archive or init packet and firmware.")
|
||||
log.Warn().Msg("Upgrade command requires either archive or init packet and firmware.")
|
||||
return
|
||||
}
|
||||
|
||||
// Encode response into connection
|
||||
|
||||
3
go.mod
3
go.mod
@@ -4,8 +4,11 @@ go 1.16
|
||||
|
||||
require (
|
||||
github.com/VividCortex/ewma v1.2.0 // indirect
|
||||
github.com/abiosoft/ishell v2.0.0+incompatible
|
||||
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db // indirect
|
||||
github.com/cheggaaa/pb/v3 v3.0.8
|
||||
github.com/fatih/color v1.12.0 // indirect
|
||||
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.0 // indirect
|
||||
github.com/godbus/dbus/v5 v5.0.4
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
|
||||
8
go.sum
8
go.sum
@@ -42,6 +42,10 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
|
||||
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
|
||||
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
|
||||
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
|
||||
github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg=
|
||||
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8=
|
||||
github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
@@ -51,8 +55,10 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
|
||||
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
|
||||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
@@ -77,6 +83,8 @@ github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
|
||||
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI=
|
||||
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.0 h1:NO5hkcB+srp1x6QmwvNZLeaOgbM8cmBTN32THzjvu2k=
|
||||
github.com/fsnotify/fsnotify v1.5.0/go.mod h1:BX0DCEr5pT4jm2CnQdVP1lFV521fcCNcyEeNp4DQQDk=
|
||||
|
||||
2
main.go
2
main.go
@@ -36,8 +36,8 @@ func init() {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
// Set config settings
|
||||
viper.AddConfigPath("/etc")
|
||||
viper.AddConfigPath("$HOME/.config")
|
||||
viper.AddConfigPath("/etc")
|
||||
viper.SetConfigName("itd")
|
||||
viper.SetConfigType("toml")
|
||||
viper.WatchConfig()
|
||||
|
||||
Reference in New Issue
Block a user