Add Footer Block options to make_block
This commit is contained in:
parent
19d77064b0
commit
efb2a51216
9 changed files with 185 additions and 12 deletions
|
|
@ -71,6 +71,8 @@ func (i info) Run(context wisski_distillery.Context) (err error) {
|
|||
context.Printf("Last Update: %v\n", info.LastUpdate.String())
|
||||
context.Printf("Last Cron: %v\n", info.LastCron.String())
|
||||
|
||||
context.Printf("Theme: %v\n", info.Theme)
|
||||
|
||||
context.Printf("Bundles: (count %d)\n", info.Statistics.Bundles.TotalBundles)
|
||||
for _, bundle := range info.Statistics.Bundles.Bundles {
|
||||
if bundle.Count == 0 {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php/extras"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
|
|
@ -18,12 +19,25 @@ var MakeBlock wisski_distillery.Command = makeBlock{}
|
|||
type makeBlock struct {
|
||||
Title string `short:"t" long:"title" description:"title of block to create"`
|
||||
Region string `short:"r" long:"region" description:"optional region to assign block to"`
|
||||
Footer bool `short:"f" long:"footer" description:"create block in the footer region"`
|
||||
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to create legal block for"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
var errFooterAndRegion = exit.Error{
|
||||
Message: "`--footer` and `--region` provided",
|
||||
ExitCode: exit.ExitCommandArguments,
|
||||
}
|
||||
|
||||
func (mb makeBlock) AfterParse() error {
|
||||
if mb.Region != "" && mb.Footer {
|
||||
return errFooterAndRegion
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (makeBlock) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: cli.Requirements{
|
||||
|
|
@ -39,6 +53,16 @@ var errBlocksGeneric = exit.Error{
|
|||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
var errBlocksFooterFailed = exit.Error{
|
||||
Message: "unable to determine footer block",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
var errBlocksNoFooter = exit.Error{
|
||||
Message: "no footer known for region",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
var errBlocksNoContent = exit.Error{
|
||||
Message: "unable to read content from standard input",
|
||||
ExitCode: exit.ExitCommandArguments,
|
||||
|
|
@ -52,10 +76,16 @@ func (mb makeBlock) Run(context wisski_distillery.Context) error {
|
|||
return errPathbuilderWissKI.Wrap(err)
|
||||
}
|
||||
|
||||
// read the content
|
||||
content, err := io.ReadAll(context.Stdin)
|
||||
if err != nil {
|
||||
return errBlocksNoContent.Wrap(err)
|
||||
// get the footer (if any)
|
||||
if mb.Footer {
|
||||
zerolog.Ctx(context.Context).Info().Msg("checking for footer")
|
||||
region, err := instance.Blocks().GetFooterRegion(context.Context, nil)
|
||||
if err != nil {
|
||||
return errBlocksFooterFailed.Wrap(err)
|
||||
}
|
||||
if region == "" {
|
||||
return errBlocksNoFooter
|
||||
}
|
||||
}
|
||||
|
||||
id := ""
|
||||
|
|
@ -63,6 +93,12 @@ func (mb makeBlock) Run(context wisski_distillery.Context) error {
|
|||
id = fmt.Sprintf("block-auto-%d", time.Now().Unix())
|
||||
}
|
||||
|
||||
// read the content
|
||||
content, err := io.ReadAll(context.Stdin)
|
||||
if err != nil {
|
||||
return errBlocksNoContent.Wrap(err)
|
||||
}
|
||||
|
||||
{
|
||||
err := instance.Blocks().Create(context.Context, nil, extras.Block{
|
||||
Info: mb.Title,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue