Introduce :new-account -t
Adding the [-t] temporary flag to the new-account command - when using -t a newly created account will not be stored into the accounts.conf Issue #134
This commit is contained in:
parent
7446a17830
commit
0771eaf24c
2 changed files with 32 additions and 16 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/widgets"
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||||
|
"git.sr.ht/~sircmpwn/getopt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -11,10 +12,17 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommandNewAccount(aerc *widgets.Aerc, args []string) error {
|
func CommandNewAccount(aerc *widgets.Aerc, args []string) error {
|
||||||
if len(args) != 1 {
|
opts, _, err := getopt.Getopts(args[1:], "t")
|
||||||
return errors.New("Usage: new-account")
|
if err != nil {
|
||||||
|
return errors.New("Usage: new-account [-t]")
|
||||||
}
|
}
|
||||||
wizard := widgets.NewAccountWizard(aerc.Config(), aerc)
|
wizard := widgets.NewAccountWizard(aerc.Config(), aerc)
|
||||||
|
for _, opt := range opts {
|
||||||
|
switch opt.Option {
|
||||||
|
case 't':
|
||||||
|
wizard.ConfigureTemporaryAccount(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
aerc.NewTab(wizard, "New account")
|
aerc.NewTab(wizard, "New account")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ type AccountWizard struct {
|
||||||
step int
|
step int
|
||||||
steps []*ui.Grid
|
steps []*ui.Grid
|
||||||
focus int
|
focus int
|
||||||
|
temporary bool
|
||||||
testing bool
|
testing bool
|
||||||
// CONFIGURE_BASICS
|
// CONFIGURE_BASICS
|
||||||
accountName *ui.TextInput
|
accountName *ui.TextInput
|
||||||
|
@ -76,6 +77,7 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
|
||||||
accountName: ui.NewTextInput("").Prompt("> "),
|
accountName: ui.NewTextInput("").Prompt("> "),
|
||||||
aerc: aerc,
|
aerc: aerc,
|
||||||
conf: conf,
|
conf: conf,
|
||||||
|
temporary: false,
|
||||||
copySent: true,
|
copySent: true,
|
||||||
email: ui.NewTextInput("").Prompt("> "),
|
email: ui.NewTextInput("").Prompt("> "),
|
||||||
fullName: ui.NewTextInput("").Prompt("> "),
|
fullName: ui.NewTextInput("").Prompt("> "),
|
||||||
|
@ -378,6 +380,10 @@ func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard {
|
||||||
return wizard
|
return wizard
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wizard *AccountWizard) ConfigureTemporaryAccount(temporary bool) {
|
||||||
|
wizard.temporary = temporary
|
||||||
|
}
|
||||||
|
|
||||||
func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
|
func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
|
||||||
if d == nil {
|
if d == nil {
|
||||||
wizard.aerc.PushStatus(" "+err.Error(), 10*time.Second).
|
wizard.aerc.PushStatus(" "+err.Error(), 10*time.Second).
|
||||||
|
@ -459,6 +465,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
|
||||||
sec.NewKey("copy-to", "Sent")
|
sec.NewKey("copy-to", "Sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !wizard.temporary {
|
||||||
f, err := os.OpenFile(accountsConf, os.O_WRONLY|os.O_CREATE, 0600)
|
f, err := os.OpenFile(accountsConf, os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wizard.errorFor(nil, err)
|
wizard.errorFor(nil, err)
|
||||||
|
@ -468,6 +475,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
|
||||||
wizard.errorFor(nil, err)
|
wizard.errorFor(nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account := config.AccountConfig{
|
account := config.AccountConfig{
|
||||||
Name: sec.Name(),
|
Name: sec.Name(),
|
||||||
|
|
Loading…
Reference in a new issue