Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions op-deployer/pkg/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ func NewApp(versionWithMeta string) *cli.App {
app.Name = "op-deployer"
app.Usage = "Tool to configure and deploy OP Chains."
app.Flags = cliapp.ProtectFlags(deployer.GlobalFlags)
app.Before = func(context *cli.Context) error {
if err := deployer.CreateCacheDir(context.String(deployer.CacheDirFlagName)); err != nil {
return err
}
return nil
}
app.Commands = []*cli.Command{
{
Name: "init",
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
Usage: "Cache directory. " +
"If set, the deployer will attempt to cache downloaded artifacts in the specified directory.",
EnvVars: PrefixEnvVar("CACHE_DIR"),
Value: EnsureDefaultCacheDir(),
Value: DefaultCacheDir(),
}
L1ChainIDFlag = &cli.Uint64Flag{
Name: L1ChainIDFlagName,
Expand Down
11 changes: 7 additions & 4 deletions op-deployer/pkg/deployer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func cwd() string {
return dir
}

func EnsureDefaultCacheDir() string {
func DefaultCacheDir() string {
var cacheDir string

homeDir, err := os.UserHomeDir()
Expand All @@ -50,9 +50,12 @@ func EnsureDefaultCacheDir() string {
cacheDir = path.Join(homeDir, ".op-deployer/cache")
}

return cacheDir
}

func CreateCacheDir(cacheDir string) error {
if err := os.MkdirAll(cacheDir, 0755); err != nil {
panic(fmt.Sprintf("failed to create cache directory %s: %v", cacheDir, err))
return fmt.Errorf("failed to create cache directory %s: %w", cacheDir, err)
}

return cacheDir
return nil
}
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
)

func TestEnsureDefaultCacheDir(t *testing.T) {
cacheDir := EnsureDefaultCacheDir()
cacheDir := DefaultCacheDir()
require.NotNil(t, cacheDir)
}
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func VerifyCLI(cliCtx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to parse l1 contracts release locator: %w", err)
}
artifactsFS, err := artifacts.Download(ctx, locator, nil, deployer.EnsureDefaultCacheDir())
artifactsFS, err := artifacts.Download(ctx, locator, nil, deployer.DefaultCacheDir())
if err != nil {
return fmt.Errorf("failed to get artifacts: %w", err)
}
Expand Down