Added ExecAndGetLines util func

pull/13/head
Paulo Truta 2021-06-10 11:45:02 +00:00
parent 4dec81e487
commit 9ef07e6052
2 changed files with 12 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package storage package storage
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -75,10 +74,7 @@ func GetDevices() []Device {
var devices []Device var devices []Device
cmdArgs := []string{"--raw", "--bytes", "--noheadings"} cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
cmdOutput := utils.Exec("lsblk", cmdArgs) scanner := utils.ExecAndGetLines("lsblk", cmdArgs)
cmdOutputReader := strings.NewReader(cmdOutput)
scanner := bufio.NewScanner(cmdOutputReader)
scanner.Split(bufio.ScanLines)
var currentDevice Device var currentDevice Device
var currentPartitions []Partition var currentPartitions []Partition

View File

@ -1,12 +1,14 @@
package utils package utils
import ( import (
"bufio"
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"strings"
"time" "time"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@ -53,6 +55,15 @@ func Exec(command string, args []string) string {
} }
func ExecAndGetLines(command string, args []string) *bufio.Scanner {
cmdOutput := Exec(command, args)
cmdOutputReader := strings.NewReader(cmdOutput)
scanner := bufio.NewScanner(cmdOutputReader)
scanner.Split(bufio.ScanLines)
return scanner
}
// DeleteEmptySlices : Given a string array, delete empty entries. // DeleteEmptySlices : Given a string array, delete empty entries.
func DeleteEmptySlices(s []string) []string { func DeleteEmptySlices(s []string) []string {
var r []string var r []string