Skip to content

Commit

Permalink
Add name/description to 'pkg init'. (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Aug 6, 2024
1 parent 0dd4bc4 commit 36314dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion commands/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ If the --project-root flag is used, initializes that directory instead.`,
Run: errorCfgRun(handler.pkgInit),
Args: cobra.NoArgs,
}
initCmd.Flags().String("name", "", "The name of the package")
initCmd.Flags().String("description", "", "The description of the package")
cmd.AddCommand(initCmd)

installCmd := &cobra.Command{
Expand Down Expand Up @@ -679,8 +681,16 @@ func (h *pkgHandler) pkgInit(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
description, err := cmd.Flags().GetString("description")
if err != nil {
return err
}

err = tpkg.InitDirectory(projectRoot, tpkgUI)
err = tpkg.InitDirectory(projectRoot, name, description, tpkgUI)
if IsAlreadyExistsError(err) {
return h.ui.ReportError(ErrorMessage(err))
} else if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/tpkg/tpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func lockPathForDir(dir string) string {

// InitDirectory initializes the project root as the root for a package or application.
// If no root is given, initializes the current directory instead.
func InitDirectory(projectRoot string, ui UI) error {
func InitDirectory(projectRoot string, name string, description string, ui UI) error {
dir := projectRoot
if dir == "" {
cwd, err := os.Getwd()
Expand All @@ -68,7 +68,13 @@ func InitDirectory(projectRoot string, ui UI) error {
ui.ReportInfo("Directory '%s' already initialized", dir)
return nil
}
err = ioutil.WriteFile(pkgPath, []byte("# Toit Package File.\n"), 0644)

spec := Spec{
path: pkgPath,
Name: name,
Description: description,
}
err = spec.WriteToFile()
if err != nil {
return err
}
Expand Down

0 comments on commit 36314dd

Please sign in to comment.