Skip to content

Commit

Permalink
Move cmd/gomi/main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed May 12, 2015
1 parent f1e0288 commit 38fe8f6
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 34 deletions.
13 changes: 7 additions & 6 deletions main.go → cmd/gomi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/b4b4r07/gomi"
"github.com/jessevdk/go-flags"
"os"
"path/filepath"
Expand All @@ -27,7 +28,7 @@ func main() {
path = args[0]
}

if err := restore(path); err != nil {
if err := gomi.Restore(path); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
Expand All @@ -43,11 +44,11 @@ func main() {
}

// Main
for _, gomi := range args {
for _, g := range args {
if opts.System {
path, err = removeTo(gomi)
path, err = gomi.RemoveTo(g)
} else {
path, err = remove(gomi)
path, err = gomi.Remove(g)
}

if err != nil {
Expand All @@ -59,8 +60,8 @@ func main() {
os.Exit(1)
}

gomi, _ = filepath.Abs(gomi)
if err := logging(gomi, path); err != nil {
g, _ = filepath.Abs(g)
if err := gomi.Logging(g, path); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"fmt"
Expand Down
10 changes: 5 additions & 5 deletions gomi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"bufio"
Expand Down Expand Up @@ -44,7 +44,7 @@ func cleanLog() error {
return nil
}

func restore(path string) error {
func Restore(path string) error {
var answer string

if err := cleanLog(); err != nil {
Expand Down Expand Up @@ -98,7 +98,7 @@ func restore(path string) error {
return nil
}

func logging(src, dest string) error {
func Logging(src, dest string) error {
// Open or create rm_log if rm_log doesn't exist
f, err := os.OpenFile(rm_log, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
Expand All @@ -123,7 +123,7 @@ func logging(src, dest string) error {
return nil
}

func remove(src string) (dest string, err error) {
func Remove(src string) (dest string, err error) {
// Check if rm_trash exists
_, err = os.Stat(rm_trash)
if os.IsNotExist(err) {
Expand Down Expand Up @@ -166,7 +166,7 @@ func remove(src string) (dest string, err error) {
return
}

func removeTo(src string) (dest string, err error) {
func RemoveTo(src string) (dest string, err error) {
// Check if src exists
_, err = os.Stat(src)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gomi_others.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !windows

package main
package gomi

import "os"

Expand Down
2 changes: 1 addition & 1 deletion gomi_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build windows

package main
package gomi

var rm_trash = `C:\ProgramData` + "/gomi"
var rm_log = rm_trash + "/log"
2 changes: 1 addition & 1 deletion quicklook.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"bufio"
Expand Down
16 changes: 8 additions & 8 deletions tty_bsd.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// +build darwin freebsd

package main
package gomi

import (
"os"
"syscall"
"unsafe"
"os"
"syscall"
"unsafe"
)

func isTty() bool {
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, os.Stdin.Fd(), uintptr(syscall.TIOCGETA), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, os.Stdin.Fd(), uintptr(syscall.TIOCGETA), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
}

func ttyReady() error {
return nil
return nil
}

func ttyTerm() {
Expand Down
16 changes: 8 additions & 8 deletions tty_linux.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// +build linux

package main
package gomi

import (
"os"
"syscall"
"unsafe"
"os"
"syscall"
"unsafe"
)

func isTty() bool {
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, os.Stdin.Fd(), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, os.Stdin.Fd(), uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
}

func ttyReady() error {
return nil
return nil
}

func ttyTerm() {
Expand Down
2 changes: 1 addition & 1 deletion tty_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion ui.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package gomi

import (
"bufio"
Expand Down

0 comments on commit 38fe8f6

Please sign in to comment.