| 1 |
package patch |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
"path/filepath" |
| 7 |
|
| 8 |
"git.sr.ht/~rjarry/aerc/commands" |
| 9 |
"git.sr.ht/~rjarry/aerc/lib/pama" |
| 10 |
) |
| 11 |
|
| 12 |
type Init struct { |
| 13 |
Force bool `opt:"-f" desc:"Overwrite any existing project."` |
| 14 |
Name string `opt:"name" required:"false"` |
| 15 |
} |
| 16 |
|
| 17 |
func init() { |
| 18 |
register(Init{}) |
| 19 |
} |
| 20 |
|
| 21 |
func (Init) Description() string { |
| 22 |
return "Create a new project." |
| 23 |
} |
| 24 |
|
| 25 |
func (Init) Context() commands.CommandContext { |
| 26 |
return commands.GLOBAL |
| 27 |
} |
| 28 |
|
| 29 |
func (Init) Aliases() []string { |
| 30 |
return []string{"init"} |
| 31 |
} |
| 32 |
|
| 33 |
func (i Init) Execute(args []string) error { |
| 34 |
cwd, err := os.Getwd() |
| 35 |
if err != nil { |
| 36 |
return fmt.Errorf("Could not get current directory: %w", err) |
| 37 |
} |
| 38 |
|
| 39 |
name := i.Name |
| 40 |
if name == "" { |
| 41 |
name = filepath.Base(cwd) |
| 42 |
} |
| 43 |
|
| 44 |
return pama.New().Init(name, cwd, i.Force) |
| 45 |
} |