Skip to content

Commit

Permalink
Support to install asciinema (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen authored Oct 20, 2021
1 parent d8794ae commit fc8b905
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pkg/os/apt/asciinema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package apt

import (
"fmt"
"github.com/linuxsuren/http-downloader/pkg/exec"
"runtime"
)

// asciinemaInstallerInUbuntu is the installer of asciinema in CentOS
type asciinemaInstallerInUbuntu struct {
count int
}

// Available check if support current platform
func (d *asciinemaInstallerInUbuntu) Available() (ok bool) {
if runtime.GOOS == "linux" {
_, err := exec.LookPath("apt-get")
ok = err == nil
}
return
}

// Install installs the asciinema
func (d *asciinemaInstallerInUbuntu) Install() (err error) {
if err = exec.RunCommand("apt-get", "update", "-y"); err != nil {
return
}
if err = exec.RunCommand("apt-get", "install", "-y",
"asciinema"); err != nil {
return
}
return
}

// Uninstall uninstalls the asciinema
func (d *asciinemaInstallerInUbuntu) Uninstall() (err error) {
err = exec.RunCommand("apt-get", "remove", "-y",
"asciinema")
return
}

// WaitForStart waits for the service be started
func (d *asciinemaInstallerInUbuntu) WaitForStart() (ok bool, err error) {
ok = true
return
}

// Start starts the asciinema service
func (d *asciinemaInstallerInUbuntu) Start() error {
fmt.Println("not supported yet")
return nil
}

// Stop stops the asciinema service
func (d *asciinemaInstallerInUbuntu) Stop() error {
fmt.Println("not supported yet")
return nil
}
1 change: 1 addition & 0 deletions pkg/os/apt/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ func SetInstallerRegistry(registry core.InstallerRegistry) {
registry.Registry("git", &gitInstallerInUbuntu{})
registry.Registry("kubectl", &kubectlInstallerInUbuntu{})
registry.Registry("bash-completion", &bashCompletionInstallerInUbuntu{})
registry.Registry("asciinema", &asciinemaInstallerInUbuntu{})
}
51 changes: 51 additions & 0 deletions pkg/os/brew/asciinema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package brew

import (
"fmt"
"github.com/linuxsuren/http-downloader/pkg/exec"
"runtime"
)

// asciinemaInstallerInMacOS is the installer of asciinema in CentOS
type asciinemaInstallerInMacOS struct {
count int
}

// Available check if support current platform
func (d *asciinemaInstallerInMacOS) Available() (ok bool) {
if runtime.GOOS == "darwin" {
_, err := exec.LookPath("brew")
ok = err == nil
}
return
}

// Install installs the asciinema
func (d *asciinemaInstallerInMacOS) Install() (err error) {
err = exec.RunCommand("brew", "install", "asciinema")
return
}

// Uninstall uninstalls the asciinema
func (d *asciinemaInstallerInMacOS) Uninstall() (err error) {
err = exec.RunCommand("brew", "remove", "asciinema")
return
}

// WaitForStart waits for the service be started
func (d *asciinemaInstallerInMacOS) WaitForStart() (ok bool, err error) {
ok = true
return
}

// Start starts the asciinema service
func (d *asciinemaInstallerInMacOS) Start() error {
fmt.Println("not supported yet")
return nil
}

// Stop stops the asciinema service
func (d *asciinemaInstallerInMacOS) Stop() error {
fmt.Println("not supported yet")
return nil
}
1 change: 1 addition & 0 deletions pkg/os/brew/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import "github.com/linuxsuren/http-downloader/pkg/os/core"
func SetInstallerRegistry(registry core.InstallerRegistry) {
registry.Registry("vim", &vimInstallerInMacOS{})
registry.Registry("bash-completion", &vimInstallerInMacOS{})
registry.Registry("asciinema", &asciinemaInstallerInMacOS{})
}

0 comments on commit fc8b905

Please sign in to comment.