@@ -8,70 +8,75 @@ import (
88 "github.com/spf13/cobra"
99)
1010
11- var architectureCmd = & cobra.Command {
12- Use : "architecture" ,
13- Aliases : []string {"arch" },
14- Short : "Shows information about CPU and OS architecture" ,
15- Hidden : true ,
16- Args : cobra .NoArgs ,
17- RunE : func (cmd * cobra.Command , args []string ) error {
18- s := system .NewSystem ()
19-
20- osArchitecture , err := s .GetArchitecture ()
21- if err != nil {
22- return fmt .Errorf ("could not get OS architecture: %w" , err )
23- }
24-
25- systemArchitecture , err := s .GetCpuArchitecture ()
26- if err != nil {
27- return fmt .Errorf ("could not get CPU architecture: %w" , err )
28- }
29-
30- fmt .Fprintf (cmd .OutOrStdout (), "You are using a %s CPU on a %s OS\n " , systemArchitecture , osArchitecture )
31-
32- return nil
33- },
11+ func newArchitectureCmd () * cobra.Command {
12+ architectureCmd := & cobra.Command {
13+ Use : "architecture" ,
14+ Aliases : []string {"arch" },
15+ Short : "Shows information about CPU and OS architecture" ,
16+ Hidden : true ,
17+ Args : cobra .NoArgs ,
18+ RunE : func (cmd * cobra.Command , args []string ) error {
19+ s := system .NewSystem ()
20+
21+ osArchitecture , err := s .GetArchitecture ()
22+ if err != nil {
23+ return fmt .Errorf ("could not get OS architecture: %w" , err )
24+ }
25+
26+ systemArchitecture , err := s .GetCpuArchitecture ()
27+ if err != nil {
28+ return fmt .Errorf ("could not get CPU architecture: %w" , err )
29+ }
30+
31+ fmt .Fprintf (cmd .OutOrStdout (), "You are using a %s CPU on a %s OS\n " , systemArchitecture , osArchitecture )
32+
33+ return nil
34+ },
35+ }
36+
37+ architectureCmd .AddCommand (newOsArchitectureCmd ())
38+ architectureCmd .AddCommand (newSystemArchitectureCmd ())
39+
40+ return architectureCmd
3441}
3542
36- var osArchitectureCommand = & cobra.Command {
37- Use : "os" ,
38- Short : "Shows OS architecture" ,
39- Args : cobra .NoArgs ,
40- RunE : func (cmd * cobra.Command , args []string ) error {
41- s := system .NewSystem ()
43+ func newOsArchitectureCmd () * cobra.Command {
44+ return & cobra.Command {
45+ Use : "os" ,
46+ Short : "Shows OS architecture" ,
47+ Args : cobra .NoArgs ,
48+ RunE : func (cmd * cobra.Command , args []string ) error {
49+ s := system .NewSystem ()
4250
43- osArchitecture , err := s .GetArchitecture ()
44- if err != nil {
45- return fmt .Errorf ("could not get OS architecture: %w" , err )
46- }
51+ osArchitecture , err := s .GetArchitecture ()
52+ if err != nil {
53+ return fmt .Errorf ("could not get OS architecture: %w" , err )
54+ }
4755
48- fmt .Fprintln (cmd .OutOrStdout (), osArchitecture )
56+ fmt .Fprintln (cmd .OutOrStdout (), osArchitecture )
4957
50- return nil
51- },
58+ return nil
59+ },
60+ }
5261}
5362
54- var systemArchitectureCommand = & cobra.Command {
55- Use : "system" ,
56- Aliases : []string {"cpu" },
57- Short : "Shows CPU architecture" ,
58- Args : cobra .NoArgs ,
59- RunE : func (cmd * cobra.Command , args []string ) error {
60- s := system .NewSystem ()
61-
62- systemArchitecture , err := s .GetCpuArchitecture ()
63- if err != nil {
64- return fmt .Errorf ("could not get CPU architecture: %w" , err )
65- }
66-
67- fmt .Fprintln (cmd .OutOrStdout (), systemArchitecture )
68-
69- return nil
70- },
71- }
72-
73- func init () {
74- rootCmd .AddCommand (architectureCmd )
75- architectureCmd .AddCommand (osArchitectureCommand )
76- architectureCmd .AddCommand (systemArchitectureCommand )
63+ func newSystemArchitectureCmd () * cobra.Command {
64+ return & cobra.Command {
65+ Use : "system" ,
66+ Aliases : []string {"cpu" },
67+ Short : "Shows CPU architecture" ,
68+ Args : cobra .NoArgs ,
69+ RunE : func (cmd * cobra.Command , args []string ) error {
70+ s := system .NewSystem ()
71+
72+ systemArchitecture , err := s .GetCpuArchitecture ()
73+ if err != nil {
74+ return fmt .Errorf ("could not get CPU architecture: %w" , err )
75+ }
76+
77+ fmt .Fprintln (cmd .OutOrStdout (), systemArchitecture )
78+
79+ return nil
80+ },
81+ }
7782}
0 commit comments