Skip to content

Commit

Permalink
remove useless return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziy1-Tan committed Jul 13, 2022
1 parent 7c84ff9 commit a551daa
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ type linuxEntry struct {

func (ery linuxEntry) String() string {
return fmt.Sprintf(`
Kernel Info:
%s
LSB Release Info:
%s
Processor Info:
%s
OS Release Info:
%s`, ery.kernel, ery.processor, ery.lsbRelease, ery.osRelease)
Kernel Info:
%s
LSB Release Info:
%s
Processor Info:
%s
OS Release Info:
%s`, ery.kernel, ery.processor, ery.lsbRelease, ery.osRelease)
}

type macosEntry struct {
Expand All @@ -77,12 +77,12 @@ type macosEntry struct {

func (ery macosEntry) String() string {
return fmt.Sprintf(`
Kernel Info:
%s
OS Version:
%s
Hardware Info:
%s`, ery.kernel, ery.osVersion, ery.hardware)
Kernel Info:
%s
OS Version:
%s
Hardware Info:
%s`, ery.kernel, ery.osVersion, ery.hardware)
}

func checkExist(fileName string) bool {
Expand Down Expand Up @@ -115,14 +115,12 @@ func getLinuxOSEntry() (*linuxEntry, error) {
kernel, err := getKernelInfo()
if err != nil {
logger.Fatalf("Failed to execute command `uname`: %s", err)
return nil, err
}
linuxEry.kernel = kernel

lsbRelease, err := exec.Command("lsb_release", "-a").Output()
if err != nil {
logger.Fatalf("Failed to execute command `lsb_release`: %s", err)
return nil, err
}

linuxEry.lsbRelease = string(lsbRelease)
Expand All @@ -131,15 +129,13 @@ func getLinuxOSEntry() (*linuxEntry, error) {
processor, err := exec.Command("cat", "/proc/version").Output()
if err != nil {
logger.Fatalf("Failed to execute command `cat /proc/version`: %s", err)
return nil, err
}
linuxEry.processor = string(processor)
}
if checkExist(releasePath) {
osRelease, err := exec.Command("cat", "/etc/os-release").Output()
if err != nil {
logger.Fatalf("Failed to execute command `cat /etc/os-release`: %s", err)
return nil, err
}
linuxEry.osRelease = string(osRelease)
}
Expand All @@ -152,21 +148,18 @@ func getMacOSEntry() (*macosEntry, error) {
kernel, err := getKernelInfo()
if err != nil {
logger.Fatalf("Failed to execute command `uname`: %s", err)
return nil, err
}
macosEry.kernel = kernel

osVersion, err := exec.Command("sw_vers").Output()
if err != nil {
logger.Fatalf("Failed to execute command `sw_vers`: %s", err)
return nil, err
}
macosEry.osVersion = string(osVersion)

hardware, err := exec.Command("sw_vers").Output()
if err != nil {
logger.Fatalf("Failed to execute command `sw_vers`: %s", err)
return nil, err
}
macosEry.hardware = string(hardware)

Expand All @@ -181,29 +174,26 @@ func doctor(ctx *cli.Context) error {
ery, err := getLinuxOSEntry()
if err != nil {
logger.Fatalf("Failed to get linux os info: %s", err)
break
}
osEry = ery.String()
case "darwin":
ery, err := getMacOSEntry()
if err != nil {
logger.Fatalf("Failed to get macos info: %s", err)
return err
}
osEry = ery.String()
case "windows":
ery, err := exec.Command("systeminfo", "/etc/os-release").Output()
if err != nil {
logger.Fatalf("Failed to execute command `systeminfo`: %s", err)
return err
}
osEry = string(ery)
}

result := fmt.Sprintf(
`
Platform: %s
OS Info:
Platform:
%s
%s
JuiceFS Version:
%s
Expand All @@ -213,29 +203,25 @@ JuiceFS Version:
st, err := os.Stat(filePath)
if err != nil {
logger.Fatalf("Failed to stat path %s: %s", filePath, err)
return err
}

if !st.IsDir() {
logger.Fatalf("Arg <output> should be a directory!")
return err
logger.Fatalf("Argument <-o|--output> should be a directory!")
}

filePath = path.Join(filePath, "doctor.log")
file, err := os.Create(filePath)
if err != nil {
logger.Fatalf("Failed to create file %s: %s", filePath, err)
return err
} else {
_, err = file.Write([]byte(result))
if err != nil {
logger.Fatalf("Failed to write file %s: %s", filePath, err)
return err
}
}
defer file.Close()

fmt.Println(result)

return err
return nil
}

0 comments on commit a551daa

Please sign in to comment.