File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package build
22
33import (
4- "errors"
54 "os"
65 "path"
76
87 "github.com/FascodeNet/alterlinux/alteriso5/cmd/build/config"
98 "github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work"
109)
1110
12- func check () error {
13- if os .Getuid () != 0 {
14- return errors .New ("this program must be run as root" )
15- }
16- return nil
17- }
18-
1911func build () error {
2012 current , err := os .Getwd ()
2113 if err != nil {
@@ -32,7 +24,7 @@ func build() error {
3224
3325 // Dummy profile
3426 profile := config.Profile {
35- Base : path .Join (current , "profile" ),
27+ Base : path .Join (current , "profile" ),
3628 InstallDir : "alter" ,
3729 }
3830
Original file line number Diff line number Diff line change 44 "fmt"
55 "os"
66
7+ "github.com/FascodeNet/alterlinux/alteriso5/cmd/check"
78 "github.com/FascodeNet/alterlinux/alteriso5/utils"
89 "github.com/spf13/cobra"
910)
@@ -19,13 +20,12 @@ func Cmd() *cobra.Command {
1920 os .Exit (1 )
2021 }, os .Interrupt )
2122
22- if err := check (); err != nil {
23- cmd .PrintErrln (err )
24- os .Exit (1 )
23+ if err := utils .CallCmd (cmd , * check .Cmd ()); err != nil {
24+ return err
2525 }
2626
2727 if err := build (); err != nil {
28- cmd . PrintErrln ( err )
28+ return err
2929 }
3030
3131 return nil
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "github.com/FascodeNet/alterlinux/alteriso5/cmd/check"
5+ "github.com/Hayao0819/nahi/cobrautils"
6+ )
7+
8+ func init () {
9+ cobrautils .AddSubCmds (check .Cmd ())
10+ }
Original file line number Diff line number Diff line change 1+ package check
2+
3+ import (
4+ "errors"
5+ "os"
6+
7+ "github.com/spf13/cobra"
8+ )
9+
10+ func check () error {
11+ if os .Getuid () != 0 {
12+ return errors .New ("this program must be run as root" )
13+ }
14+ return nil
15+ }
16+
17+ func Cmd () * cobra.Command {
18+ cmd := cobra.Command {
19+ Use : "check" ,
20+ Short : "Check if the system is ready to build the ISO" ,
21+ SilenceUsage : true ,
22+ SilenceErrors : true ,
23+ RunE : func (cmd * cobra.Command , args []string ) error {
24+ return check ()
25+ },
26+ }
27+
28+ return & cmd
29+ }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ package check
Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import "github.com/spf13/cobra"
4+
5+ func CallCmd (me * cobra.Command , target cobra.Command , args ... string ) error {
6+ target .SetOut (me .OutOrStdout ())
7+ target .SetErr (me .OutOrStderr ())
8+ target .SetIn (me .InOrStdin ())
9+ target .SetArgs (args )
10+ return target .Execute ()
11+ }
You can’t perform that action at this time.
0 commit comments