-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codex init command, update to new upload API
- Loading branch information
Showing
6 changed files
with
141 additions
and
31 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,77 @@ | ||
package codex | ||
|
||
import ( | ||
"github.com/pathbird/pbauthor/internal/auth" | ||
"github.com/pathbird/pbauthor/internal/codex" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"path/filepath" | ||
) | ||
|
||
var codexInitConfig struct { | ||
systemPackages []string | ||
codexName string | ||
} | ||
|
||
var codexInitCmd = &cobra.Command{ | ||
Use: "init [<path>]", | ||
Short: "initialize a codex configuration file", | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// If no dir is specified, use current directory. | ||
if len(args) == 0 { | ||
args = append(args, ".") | ||
} | ||
|
||
if len(args) != 1 { | ||
return cmd.Usage() | ||
} | ||
|
||
dir, err := filepath.Abs(args[0]) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid codex directory") | ||
} | ||
|
||
auth, err := auth.GetAuth() | ||
if err != nil { | ||
return err | ||
} | ||
if auth == nil { | ||
return errors.New("not authenticated") | ||
} | ||
|
||
config, err := codex.InitConfig(dir) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to initialize codex config") | ||
} | ||
|
||
if len(codexInitConfig.systemPackages) != 0 { | ||
config.Kernel.SystemPackages = codexInitConfig.systemPackages | ||
} | ||
|
||
if codexInitConfig.codexName != "" { | ||
config.Upload.Name = codexInitConfig.codexName | ||
} | ||
|
||
if err := config.Save(); err != nil { | ||
return errors.Wrap(err, "failed to save codex config") | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
codexInitCmd.Flags().StringArrayVar( | ||
&codexInitConfig.systemPackages, | ||
"system-packages", | ||
[]string{}, | ||
"a list of additional system packages to install", | ||
) | ||
codexInitCmd.Flags().StringVar( | ||
&codexInitConfig.codexName, | ||
"name", | ||
"", | ||
"the name of the codex as displayed in the Pathbird UI", | ||
) | ||
Cmd.AddCommand(codexInitCmd) | ||
} |
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
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