generated from kurtosis-tech/package-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dive context manager
- Loading branch information
1 parent
eac1065
commit 8e88421
Showing
7 changed files
with
264 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package common | ||
|
||
import ( | ||
"path/filepath" | ||
"sync" | ||
) | ||
|
||
var ( | ||
CliContext *Cli | ||
|
||
initOnce sync.Once | ||
) | ||
|
||
type Cli struct { | ||
log Logger | ||
spinner Spinner | ||
context Context | ||
fileHandler FileHandler | ||
} | ||
|
||
func initCli() (*Cli, error) { | ||
fileHandler := NewDiveFileHandler() | ||
|
||
pwd, err := fileHandler.GetPwd() | ||
|
||
if err != nil { | ||
return nil, WrapMessageToError(err, "Failed To Initialize CLi") | ||
} | ||
errorLogFilePath := filepath.Join(pwd, DiveLogDirectory, DiveErrorLogFile) | ||
infoLogFilePath := filepath.Join(pwd, DiveLogDirectory, DiveDitLogFile) | ||
|
||
return &Cli{ | ||
log: NewDiveLogger(infoLogFilePath, errorLogFilePath), | ||
spinner: NewDiveSpinner(), | ||
context: NewDiveContext1(), | ||
fileHandler: fileHandler, | ||
}, nil | ||
} | ||
|
||
func GetCli() (*Cli, error) { | ||
var err error | ||
initOnce.Do(func() { | ||
CliContext, err = initCli() | ||
}) | ||
|
||
if err != nil { | ||
return nil, WrapMessageToError(err, "Failed To Retrieve Cli") | ||
} | ||
|
||
return CliContext, nil | ||
} | ||
|
||
func (c *Cli) Logger() Logger { | ||
return c.log | ||
} | ||
|
||
func (c *Cli) Spinner() Spinner { | ||
return c.spinner | ||
} | ||
|
||
func (c *Cli) Context() Context { | ||
return c.context | ||
} | ||
|
||
func (c *Cli) FileHandler() FileHandler { | ||
return c.fileHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.