Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat [close #50, #54] Several fixes #71

Merged
merged 6 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 30 additions & 7 deletions cmd/pico.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package cmd
*/

import (
"errors"
"fmt"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -77,6 +78,7 @@ func NewPicoCommand() []*cmdr.Command {
vso.Trans("pico.run.description"),
handleFunc(),
)
runCmd.Flags().SetInterspersed(false)

exportCmd := cmdr.NewCommand(
"export",
Expand Down Expand Up @@ -188,10 +190,20 @@ func picoExport(cmd *cobra.Command, args []string) error {

err := core.PicoExport(app, bin)
if err != nil {
return err
var errMsg string
if app != "" {
errMsg = vso.Trans("pico.error.exportingApp", err.Error())
} else {
errMsg = vso.Trans("pico.error.exportingBin", err.Error())
}
return errors.New(errMsg)
}

cmdr.Success.Println(vso.Trans("pico.info.exported"))
if app != "" {
cmdr.Success.Printf(vso.Trans("pico.info.exported"), app)
} else {
cmdr.Success.Printf(vso.Trans("pico.info.exported"), bin)
}
return nil
}

Expand All @@ -206,10 +218,20 @@ func picoUnexport(cmd *cobra.Command, args []string) error {

err := core.PicoUnexport(app, bin)
if err != nil {
return err
var errMsg string
if app != "" {
errMsg = vso.Trans("pico.error.unexportingApp", err.Error())
} else {
errMsg = vso.Trans("pico.error.unexportingBin", err.Error())
}
return errors.New(errMsg)
}

cmdr.Success.Println(vso.Trans("pico.info.unexported"))
if app != "" {
cmdr.Success.Printf(vso.Trans("pico.info.unexported"), app)
} else {
cmdr.Success.Printf(vso.Trans("pico.info.unexported"), bin)
}
return nil
}

Expand All @@ -219,9 +241,10 @@ func runPicoCmd(command string, cmd *cobra.Command, args []string) error {
return err
}

if command == "shell" {
switch command {
case "shell":
return pico.Enter()
} else if command == "run" {
case "run":
_, err := pico.Exec(false, args...)
return err
}
Expand Down Expand Up @@ -256,7 +279,7 @@ func runPicoCmd(command string, cmd *cobra.Command, args []string) error {
case "upgrade":
realCommand = pkgManager.CmdUpgrade
default:
return fmt.Errorf(vso.Trans("pico.errors.unknownCommand"), command)
return fmt.Errorf(vso.Trans("pico.error.unknownCommand"), command)
}

if command == "remove" {
Expand Down
20 changes: 10 additions & 10 deletions cmd/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,45 +376,45 @@ func newTask(cmd *cobra.Command, args []string) error {

if name == "" {
if !assumeYes {
cmdr.Info.Println(vso.Trans("stacks.new.info.askName"))
cmdr.Info.Println(vso.Trans("tasks.stacks.new.info.askName"))
reader := bufio.NewReader(os.Stdin)
name, _ = reader.ReadString('\n')
if name == "" {
cmdr.Error.Println(vso.Trans("stacks.new.error.emptyName"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.emptyName"))
return nil
}
} else {
cmdr.Error.Println(vso.Trans("stacks.new.error.noName"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.noName"))
return nil
}
}

if description == "" {
if !assumeYes {
cmdr.Info.Println(vso.Trans("stacks.new.info.askDescription"))
cmdr.Info.Println(vso.Trans("tasks.stacks.new.info.askDescription"))
reader := bufio.NewReader(os.Stdin)
description, _ = reader.ReadString('\n')
if description == "" {
cmdr.Error.Println(vso.Trans("stacks.new.error.emptyDescription"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.emptyDescription"))
return nil
}
} else {
cmdr.Error.Println(vso.Trans("stacks.new.error.noDescription"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.noDescription"))
return nil
}
}

if command == "" {
if !assumeYes {
cmdr.Info.Println(vso.Trans("stacks.new.info.askCommand"))
cmdr.Info.Println(vso.Trans("tasks.stacks.new.info.askCommand"))
reader := bufio.NewReader(os.Stdin)
command, _ = reader.ReadString('\n')
if command == "" {
cmdr.Error.Println(vso.Trans("stacks.new.error.emptyCommand"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.emptyCommand"))
return nil
}
} else {
cmdr.Error.Println(vso.Trans("stacks.new.error.noCommand"))
cmdr.Error.Println(vso.Trans("tasks.stacks.new.error.noCommand"))
return nil
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ func newTask(cmd *cobra.Command, args []string) error {
return err
}

fmt.Printf(vso.Trans("stacks.new.info.taskCreated"), name)
fmt.Printf(vso.Trans("tasks.stacks.new.info.taskCreated"), name)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/pico.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package core

import (
"github.com/vanilla-os/apx/core"
"github.com/vanilla-os/apx/v2/core"
)

func GetPico() (*core.SubSystem, error) {
Expand Down
11 changes: 5 additions & 6 deletions core/task-checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package core

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -90,18 +89,18 @@ func IsNetworkUp() bool {
func GetBatteryStats() (bool, bool, bool) {
battery, lowBattery, fullBattery := false, false, false

files, err := ioutil.ReadDir("/sys/class/power_supply/")
files, err := os.ReadDir("/sys/class/power_supply/")
if err == nil {
for _, file := range files {
if strings.Contains(file.Name(), "BAT") {
status, err := ioutil.ReadFile(path.Join("/sys/class/power_supply/", file.Name(), "status"))
status, err := os.ReadFile(path.Join("/sys/class/power_supply/", file.Name(), "status"))
if err == nil {
if strings.Contains(string(status), "Discharging") {
battery = true
}
}

capacity, err := ioutil.ReadFile(path.Join("/sys/class/power_supply/", file.Name(), "capacity"))
capacity, err := os.ReadFile(path.Join("/sys/class/power_supply/", file.Name(), "capacity"))
if err == nil {
percent, err := strconv.Atoi(strings.TrimSpace(string(capacity)))
if err == nil {
Expand Down Expand Up @@ -201,7 +200,7 @@ func IsInternetUnderHighUsage() (bool, int) {

// IsMemoryUnderHighUsage checks if the memory is being used (false if exceeds 50%)
func IsMemoryUnderHighUsage() (bool, int) {
out, err := ioutil.ReadFile("/proc/meminfo")
out, err := os.ReadFile("/proc/meminfo")
if err != nil {
return false, 0
}
Expand Down Expand Up @@ -255,7 +254,7 @@ func IsCPUUnderHighUsage() (bool, int) {

// GetCPUTemp gets the CPU temperature
func GetCPUTemp() int {
b, err := ioutil.ReadFile("/sys/class/thermal/thermal_zone0/temp")
b, err := os.ReadFile("/sys/class/thermal/thermal_zone0/temp")
if err != nil {
return 0
}
Expand Down
8 changes: 7 additions & 1 deletion core/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -338,5 +339,10 @@ func getUserTasksLocation() string {
return ""
}

return "/home/" + curUser + TasksLocation
location := filepath.Join("/home", curUser, TasksLocation)
if _, err := os.Stat(location); os.IsNotExist(err) {
os.MkdirAll(location, 0755)
}

return location
}
2 changes: 1 addition & 1 deletion core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func AskConfirmation(s string, norm bool) bool {
defResponse = "n"
}
fmt.Scanln(&response)
if strings.ToLower(response) != strings.ToLower(defResponse) && len(strings.TrimSpace(response)) != 0 {
if !strings.EqualFold(response, defResponse) && len(strings.TrimSpace(response)) != 0 {
return !norm
}
return norm
Expand Down
5 changes: 3 additions & 2 deletions core/waydroid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package core
import (
"encoding/json"
"fmt"
"github.com/vanilla-os/apx/core"
bolt "go.etcd.io/bbolt"
"os"
"strings"

"github.com/vanilla-os/apx/v2/core"
bolt "go.etcd.io/bbolt"
)

type BucketNotFoundError struct {
Expand Down
41 changes: 24 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
module github.com/vanilla-os/vso

go 1.18
go 1.21

toolchain go1.21.1

require (
github.com/BurntSushi/toml v0.3.1
github.com/BurntSushi/toml v1.3.2
github.com/buger/jsonparser v1.1.1
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.7.0
github.com/vanilla-os/apx v1.7.0-1.0.20230921133324-c1323dc41f51
github.com/spf13/cobra v1.8.0
github.com/vanilla-os/apx/v2 v2.1.0
github.com/vanilla-os/orchid v0.4.0
go.etcd.io/bbolt v1.3.7
go.etcd.io/bbolt v1.3.8
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/fitv/go-i18n v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pterm/pterm v0.12.53 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pterm/pterm v0.12.71 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.13.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -46,5 +53,5 @@ require (
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0
github.com/spf13/viper v1.18.1
)
Loading
Loading