mirror of https://github.com/writeas/writefreely
pull/261/head
parent
9fb12eea74
commit
6173405794
@ -0,0 +1,63 @@ |
||||
/* |
||||
* Copyright © 2020 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/writeas/writefreely" |
||||
|
||||
"github.com/urfave/cli/v2" |
||||
) |
||||
|
||||
var ( |
||||
cmdConfig cli.Command = cli.Command{ |
||||
Name: "config", |
||||
Usage: "config management tools", |
||||
Subcommands: []*cli.Command{ |
||||
&cmdConfigGenerate, |
||||
&cmdConfigInteractive, |
||||
}, |
||||
} |
||||
|
||||
cmdConfigGenerate cli.Command = cli.Command{ |
||||
Name: "generate", |
||||
Aliases: []string{"gen"}, |
||||
Usage: "Generate a basic configuration", |
||||
Action: genConfigAction, |
||||
} |
||||
|
||||
cmdConfigInteractive cli.Command = cli.Command{ |
||||
Name: "interactive", |
||||
Aliases: []string{"i"}, |
||||
Usage: "Interactive configuration process", |
||||
Action: interactiveConfigAction, |
||||
Flags: []cli.Flag{ |
||||
&cli.StringFlag{ |
||||
Name: "sections", |
||||
Value: "server db app", |
||||
Usage: "Which sections of the configuration to go through (requires --config)\n" + |
||||
"valid values are any combination of 'server', 'db' and 'app' \n" + |
||||
"example: writefreely --config --sections \"db app\"", |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
) |
||||
|
||||
func genConfigAction(c *cli.Context) error { |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.CreateConfig(app) |
||||
} |
||||
|
||||
func interactiveConfigAction(c *cli.Context) error { |
||||
app := writefreely.NewApp(c.String("c")) |
||||
writefreely.DoConfig(app, c.String("sections")) |
||||
return nil |
||||
} |
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Copyright © 2020 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/writeas/writefreely" |
||||
|
||||
"github.com/urfave/cli/v2" |
||||
) |
||||
|
||||
var ( |
||||
cmdDB cli.Command = cli.Command{ |
||||
Name: "db", |
||||
Usage: "db management tools", |
||||
Subcommands: []*cli.Command{ |
||||
&cmdDBInit, |
||||
&cmdDBMigrate, |
||||
}, |
||||
} |
||||
|
||||
cmdDBInit cli.Command = cli.Command{ |
||||
Name: "init", |
||||
Usage: "Initialize Database", |
||||
Action: initDBAction, |
||||
} |
||||
|
||||
cmdDBMigrate cli.Command = cli.Command{ |
||||
Name: "migrate", |
||||
Usage: "Migrate Database", |
||||
Action: migrateDBAction, |
||||
} |
||||
) |
||||
|
||||
func initDBAction(c *cli.Context) error { |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.CreateSchema(app) |
||||
} |
||||
|
||||
func migrateDBAction(c *cli.Context) error { |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.Migrate(app) |
||||
} |
@ -0,0 +1,40 @@ |
||||
/* |
||||
* Copyright © 2020 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/writeas/writefreely" |
||||
|
||||
"github.com/urfave/cli/v2" |
||||
) |
||||
|
||||
var ( |
||||
cmdKeys cli.Command = cli.Command{ |
||||
Name: "keys", |
||||
Usage: "key management tools", |
||||
Subcommands: []*cli.Command{ |
||||
&cmdGenerateKeys, |
||||
}, |
||||
} |
||||
|
||||
cmdGenerateKeys cli.Command = cli.Command{ |
||||
Name: "generate", |
||||
Aliases: []string{"gen"}, |
||||
Usage: "Generate encryption and authentication keys", |
||||
Action: genKeysAction, |
||||
} |
||||
|
||||
) |
||||
|
||||
func genKeysAction(c *cli.Context) error { |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.GenerateKeyFiles(app) |
||||
} |
@ -0,0 +1,89 @@ |
||||
/* |
||||
* Copyright © 2020 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/writeas/writefreely" |
||||
|
||||
"github.com/urfave/cli/v2" |
||||
) |
||||
|
||||
var ( |
||||
cmdUser cli.Command = cli.Command{ |
||||
Name: "user", |
||||
Usage: "user management tools", |
||||
Subcommands: []*cli.Command{ |
||||
&cmdAddUser, |
||||
&cmdDelUser, |
||||
&cmdResetPass, |
||||
// TODO: possibly add a user list command
|
||||
}, |
||||
} |
||||
|
||||
cmdAddUser cli.Command = cli.Command{ |
||||
Name: "add", |
||||
Usage: "Add new user", |
||||
Aliases: []string{"a"}, |
||||
Flags: []cli.Flag{ |
||||
&cli.BoolFlag{ |
||||
Name: "admin", |
||||
Value: false, |
||||
Usage: "Create admin user", |
||||
}, |
||||
}, |
||||
Action: addUserAction, |
||||
} |
||||
|
||||
cmdDelUser cli.Command = cli.Command{ |
||||
Name: "delete", |
||||
Usage: "Delete user", |
||||
Aliases: []string{"del", "d"}, |
||||
Action: delUserAction, |
||||
} |
||||
|
||||
cmdResetPass cli.Command = cli.Command{ |
||||
Name: "reset-pass", |
||||
Usage: "Reset user's password", |
||||
Aliases: []string{"resetpass", "reset"}, |
||||
Action: resetPassAction, |
||||
} |
||||
) |
||||
|
||||
func addUserAction(c *cli.Context) error { |
||||
credentials := "" |
||||
if c.NArg() > 0 { |
||||
credentials = c.Args().Get(0) |
||||
} |
||||
username, password, err := parseCredentials(credentials) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.CreateUser(app, username, password, c.Bool("admin")) |
||||
} |
||||
|
||||
func delUserAction(c *cli.Context) error { |
||||
username := "" |
||||
if c.NArg() > 0 { |
||||
username = c.Args().Get(0) |
||||
} |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.DoDeleteAccount(app, username) |
||||
} |
||||
|
||||
func resetPassAction(c *cli.Context) error { |
||||
username := "" |
||||
if c.NArg() > 0 { |
||||
username = c.Args().Get(0) |
||||
} |
||||
app := writefreely.NewApp(c.String("c")) |
||||
return writefreely.ResetPassword(app, username) |
||||
} |
@ -0,0 +1,49 @@ |
||||
/* |
||||
* Copyright © 2020 A Bunch Tell LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/writeas/web-core/log" |
||||
"github.com/writeas/writefreely" |
||||
|
||||
"github.com/gorilla/mux" |
||||
"github.com/urfave/cli/v2" |
||||
) |
||||
|
||||
var ( |
||||
cmdServe cli.Command = cli.Command{ |
||||
Name: "serve", |
||||
Aliases: []string{"web"}, |
||||
Usage: "Run web application", |
||||
Action: serveAction, |
||||
} |
||||
) |
||||
|
||||
func serveAction(c *cli.Context) error { |
||||
// Initialize the application
|
||||
app := writefreely.NewApp(c.String("c")) |
||||
var err error |
||||
log.Info("Starting %s...", writefreely.FormatVersion()) |
||||
app, err = writefreely.Initialize(app, c.Bool("debug")) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
// Set app routes
|
||||
r := mux.NewRouter() |
||||
writefreely.InitRoutes(app, r) |
||||
app.InitStaticRoutes(r) |
||||
|
||||
// Serve the application
|
||||
writefreely.Serve(app, r) |
||||
|
||||
return nil |
||||
} |
Loading…
Reference in new issue