mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-27 07:06:52 +02:00
Added ExecAndGetLines util func
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -75,10 +74,7 @@ func GetDevices() []Device {
|
||||
var devices []Device
|
||||
|
||||
cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
|
||||
cmdOutput := utils.Exec("lsblk", cmdArgs)
|
||||
cmdOutputReader := strings.NewReader(cmdOutput)
|
||||
scanner := bufio.NewScanner(cmdOutputReader)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
scanner := utils.ExecAndGetLines("lsblk", cmdArgs)
|
||||
|
||||
var currentDevice Device
|
||||
var currentPartitions []Partition
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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.
|
||||
func DeleteEmptySlices(s []string) []string {
|
||||
var r []string
|
||||
|
||||
Reference in New Issue
Block a user