6 Commits

Author SHA1 Message Date
Wanjohi
1ff9878359 Merge ed1a8e1e4a into 852478c784 2024-06-12 14:43:46 -03:00
Wanjohi
852478c784 feat: Add specs generator 2024-06-04 03:55:49 +03:00
Wanjohi
ed1a8e1e4a feat: Add run command 2024-06-04 02:29:05 +03:00
Wanjohi
017c6c6b0d feat: Add padding 2024-06-04 02:18:21 +03:00
Wanjohi
a61c44bfe8 feat: Add neofetch with ASCII command 2024-06-03 00:33:51 +03:00
Wanjohi
4c723d8bc8 feat: Write cli executable as a go program. 2024-06-02 00:59:56 +03:00
8 changed files with 320 additions and 21 deletions

21
LICENSE
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 netris
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22
cmd/nestri.ascii Normal file
View File

@@ -0,0 +1,22 @@
:*@@@@@*-
+@@@@@@@@@@#=.
:@@@@@@@@@@@@@@%+:
.:--. .#@@@@:.=*@@@@@@@@@*-
-%@@@@@@*-. .=#@. :+#@@@@@@@@#+.
*@@@@@@@@@@@%+: .=#@@@@@@@@%=
@@@@@@#@@@@@@@@@*-. -*@@@@@@@*
@@@@@* :+%@@@@@@@@%+: +@@@@@@
@@@@@+ -#@@@@@@@@@*. :+@@@@@@@*
@@@@@+ -+%@@@*=. .=*@@@@@@@@%=
@@@@@+ :*=. :+%@@@@@@@@#=.
@@@@@+ -@@@%- +@@@@@@@@@#-
@@@@@+ -@@@@@ @@@@@@%*- -*%%*.
@@@@@* -@@@@@: @@@#=. +@@@@@@@=
@@@@@* . -@@@@@: +: .+@@@@@@
@@@@@#=*%* -@@@@@- :+@@@@@@%
%@@@@@@@@+ -@@@@@- .-*@@@@@@@@#.
.*@@@@@@@+ -@@@@@- .+%@@@@@@@@%+.
.=+**+- :@@@@@= .-*%@@@@@@@@#=.
:@@@@@%%@@@@@@@@%+-
%@@@@@@@@@@@#=.
.+%@@@@@%*-

149
cmd/root.go Normal file
View File

@@ -0,0 +1,149 @@
/*
Copyright © 2024 Nestri <>
*/
package cmd
import (
_ "embed"
"fmt"
"os"
"strings"
"sync"
"github.com/netrisdotme/cli/pkg/specs"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/muesli/termenv"
"github.com/spf13/cobra"
)
//go:embed nestri.ascii
var art string
// rootCmd represents the base command when called without any subcommands
// For a good reference point, start here: https://github.com/charmbracelet/taskcli/blob/main/cmds.go
var rootCmd = &cobra.Command{
Use: "nestri",
Short: "A CLI tool to manage your cloud gaming service",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
// this is for the "nestri neofetch" subcommand, has no arguments
var neoFetchCmd = &cobra.Command{
Use: "neofetch",
Short: "Show important system information",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
lipgloss.SetColorProfile(termenv.TrueColor)
// baseStyle := lipgloss.NewStyle().
// MarginTop(1).
// MarginRight(4).
// MarginBottom(1).
// MarginLeft(4)
var (
b strings.Builder
lines = strings.Split(art, "\n")
colors = []string{"#F8481C", "#F74127", "#F53B30", "#F23538", "#F02E40"}
step = len(lines) / len(colors)
)
for i, l := range lines {
n := clamp(0, len(colors)-1, i/step)
b.WriteString(colorize(colors[n], l))
b.WriteRune('\n')
}
t := table.New().
Border(lipgloss.HiddenBorder()).BorderStyle(lipgloss.NewStyle().Width(3))
info := &specs.Specs{}
infoChan := make(chan specs.Specs, 1)
var wg sync.WaitGroup
wg.Add(1)
go getSpecs(info, infoChan, &wg)
wg.Wait()
newInfo := <-infoChan
t.Row(b.String(), newInfo.GPU)
fmt.Print(t)
return nil
},
}
// this is the "nestri run" subcommand, takes no arguments for now
var runCmd = &cobra.Command{
Use: "run",
Short: "Run a game using nestri",
Args: cobra.NoArgs,
//For now just show the "help"
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.AddCommand(neoFetchCmd)
rootCmd.AddCommand(runCmd)
//If you want to add subcommands to run for example "netri run -fsr" do it like this
// runCmd.Flags().BoolP("fsr", "f", false, "Run the Game with FSR enabled or not")
}
func colorize(c, s string) string {
return lipgloss.NewStyle().Foreground(lipgloss.Color(c)).Render(s)
}
func clamp(v, low, high int) int {
if high < low {
low, high = high, low
}
return min(high, max(low, v))
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func getSpecs(info *specs.Specs, infoChan chan specs.Specs, wg *sync.WaitGroup) {
defer wg.Done()
sys := specs.New()
// info.Userhost = getUserHostname()
// info.OS = getOSName()
// info.Kernel = getKernelVersion()
// info.Uptime = getUptime()
// info.Shell = getShell()
// info.CPU = getCPUName()
// info.RAM = getMemStats()
info.GPU, _ = sys.GetGPUInfo()
// info.SystemArch, _ = getSystemArch()
// info.DiskUsage, _ = getDiskUsage()
infoChan <- *info
}

18
go.mod Normal file
View File

@@ -0,0 +1,18 @@
module github.com/netrisdotme/cli
go 1.22.2
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.11.0 // indirect
github.com/charmbracelet/x/ansi v0.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.19.0 // indirect
)

30
go.sum Normal file
View File

@@ -0,0 +1,30 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/ZqwWWYTG4g=
github.com/charmbracelet/lipgloss v0.11.0/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8=
github.com/charmbracelet/x/ansi v0.1.1 h1:CGAduulr6egay/YVbGc8Hsu8deMg1xZ/bkaXTPi1JDk=
github.com/charmbracelet/x/ansi v0.1.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

11
main.go Normal file
View File

@@ -0,0 +1,11 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package main
import "github.com/netrisdotme/cli/cmd"
func main() {
cmd.Execute()
}

76
pkg/specs/system.go Normal file
View File

@@ -0,0 +1,76 @@
package specs
import (
"fmt"
"os/exec"
"runtime"
"strings"
)
type SysSpecs struct {
osx string
}
func New() *SysSpecs {
return &SysSpecs{osx: runtime.GOOS}
}
func (s SysSpecs) GetGPUInfo() (string, error) {
var output []byte
var err error
switch s.osx {
case "windows":
output, err = exec.Command("wmic", "path", "win32_VideoController", "get", "name").Output()
if err != nil {
return "", fmt.Errorf("error retrieving GPU information on Windows: %v", err)
}
case "darwin":
output, err = exec.Command("system_profiler", "SPDisplaysDataType").Output()
if err != nil {
return "", fmt.Errorf("error retrieving GPU information on macOS: %v", err)
}
case "linux":
output, err = exec.Command("lspci", "-vnn").Output()
if err != nil {
return "", fmt.Errorf("error retrieving GPU information on Linux: %v", err)
}
default:
return "", fmt.Errorf("error: GPU information retrieval not implemented for %s", runtime.GOOS)
}
outputStr := strings.TrimSpace(string(output))
if s.osx == "windows" {
lines := strings.Split(outputStr, "\r\n")[1:]
gpuName := strings.TrimSpace(strings.Join(lines, " "))
return gpuName, nil
}
if s.osx == "darwin" {
lines := strings.Split(outputStr, "\n")
for _, line := range lines {
if strings.Contains(line, "Chipset Model:") {
fields := strings.Split(line, ":")
if len(fields) >= 2 {
gpuName := strings.TrimSpace(fields[1])
return gpuName, nil
}
}
}
return "", fmt.Errorf("error parsing GPU information on macOS")
}
lines := strings.Split(outputStr, "\n")
for _, line := range lines {
if strings.Contains(line, "VGA compatible controller") {
fields := strings.Fields(line)
if len(fields) > 2 {
gpuName := strings.Join(fields[2:], " ")
return gpuName, nil
}
}
}
return "", fmt.Errorf("error parsing GPU information on Linux")
}

14
pkg/specs/types.go Normal file
View File

@@ -0,0 +1,14 @@
package specs
type Specs struct {
Userhost string
OS string
Kernel string
Uptime string
Shell string
CPU string
RAM string
GPU string
SystemArch string
DiskUsage string
}