diff --git a/cmd/content/create.go b/cmd/content/create.go index 6466091..bf03de7 100644 --- a/cmd/content/create.go +++ b/cmd/content/create.go @@ -45,6 +45,11 @@ func newCreateCommand(cli labcli.CLI) *cobra.Command { opts.dir = filepath.Join(cwd, opts.name) } } + if absDir, err := filepath.Abs(opts.dir); err != nil { + return labcli.WrapStatusError(fmt.Errorf("couldn't get the absolute path of %s: %w", opts.dir, err)) + } else { + opts.dir = absDir + } return labcli.WrapStatusError(runCreateContent(cmd.Context(), cli, &opts)) }, @@ -127,7 +132,7 @@ func createChallenge(ctx context.Context, cli labcli.CLI, opts *createOptions) e if err := cli.Client().PutMarkdown(ctx, api.PutMarkdownRequest{ Kind: "challenge", - Name: opts.name, + Name: ch.Name, Content: `--- title: Sample Challenge 444 description: | diff --git a/cmd/content/list.go b/cmd/content/list.go index 8b07670..b980c10 100644 --- a/cmd/content/list.go +++ b/cmd/content/list.go @@ -19,9 +19,10 @@ func newListCommand(cli labcli.CLI) *cobra.Command { var opts listOptions cmd := &cobra.Command{ - Use: "list [--kind challenge|tutorial|course]", - Short: "List authored content, possibly filtered by kind.", - Args: cobra.NoArgs, + Use: "list [--kind challenge|tutorial|course]", + Aliases: []string{"ls"}, + Short: "List authored content, possibly filtered by kind.", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return labcli.WrapStatusError(runListContent(cmd.Context(), cli, &opts)) }, diff --git a/cmd/content/remove.go b/cmd/content/remove.go index 4954b6e..a99b4b1 100644 --- a/cmd/content/remove.go +++ b/cmd/content/remove.go @@ -19,9 +19,10 @@ func newRemoveCommand(cli labcli.CLI) *cobra.Command { var opts removeOptions cmd := &cobra.Command{ - Use: "remove [flags] ", - Short: "Remove a piece of content you authored.", - Args: cobra.ExactArgs(2), + Use: "remove [flags] ", + Aliases: []string{"rm"}, + Short: "Remove a piece of content you authored.", + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { if err := opts.kind.Set(args[0]); err != nil { return labcli.WrapStatusError(err) @@ -32,13 +33,23 @@ func newRemoveCommand(cli labcli.CLI) *cobra.Command { }, } + flags := cmd.Flags() + + flags.BoolVarP( + &opts.force, + "force", + "f", + false, + "Remove without confirmation.", + ) + return cmd } func runRemoveContent(ctx context.Context, cli labcli.CLI, opts *removeOptions) error { - cli.PrintAux("Removing %s %s...\n", opts.kind, opts.name) - if !opts.force { + cli.PrintAux("Removing %s %s...\n", opts.kind, opts.name) + if !cli.Confirm( "This action is irreversible. Are you sure?", "Yes", "No",