-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added new subcommand remove to commmad kraft pkg
Signed-off-by: Md Sahil <mohdssahil1@gmail.com>
- Loading branch information
1 parent
ad4206d
commit f27f7f6
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package remove | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"kraftkit.sh/cmdfactory" | ||
"kraftkit.sh/packmanager" | ||
"kraftkit.sh/unikraft/app" | ||
) | ||
|
||
type Remove struct { | ||
Workdir string `long:"workdir" short:"w" usage:"workdir location to remove pkg from that location"` | ||
Kraftfile string `long:"kraftfile" short:"k" usage:"Set an alternative path of the Kraftfile"` | ||
} | ||
|
||
func New() *cobra.Command { | ||
cmd, err := cmdfactory.New(&Remove{}, cobra.Command{ | ||
Short: "Remove a library dependency from the project directory", | ||
Use: "remove [FLAGS] [PACKAGE]", | ||
Aliases: []string{"rm"}, | ||
Args: cmdfactory.MinimumArgs(1, "package name is not specified to remove from the project"), | ||
Annotations: map[string]string{ | ||
cmdfactory.AnnotationHelpGroup: "pkg", | ||
}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (opts *Remove) Pre(cmd *cobra.Command, _ []string) error { | ||
ctx, err := packmanager.WithDefaultUmbrellaManagerInContext(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
cmd.SetContext(ctx) | ||
return nil | ||
} | ||
|
||
func (opts *Remove) Run(cmd *cobra.Command, args []string) error { | ||
var workdir string | ||
var err error | ||
|
||
if len(opts.Workdir) > 0 { | ||
workdir = opts.Workdir | ||
} | ||
|
||
if workdir == "." || workdir == "./" || workdir == "" { | ||
workdir, err = os.Getwd() | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
ctx := cmd.Context() | ||
|
||
popts := []app.ProjectOption{} | ||
|
||
if len(opts.Kraftfile) > 0 { | ||
popts = append(popts, app.WithProjectKraftfile(opts.Kraftfile)) | ||
} else { | ||
popts = append(popts, app.WithProjectDefaultKraftfiles()) | ||
} | ||
|
||
project, err := app.NewProjectFromOptions( | ||
ctx, | ||
append(popts, app.WithProjectWorkdir(workdir))..., | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = project.RemoveLibrary(ctx, args[0]); err != nil { | ||
return err | ||
} | ||
|
||
return project.Save() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ const ( | |
// Built-in paths | ||
VendorDir = ".unikraft" | ||
BuildDir = ".unikraft/build" | ||
LibsDir = ".unikraft/libs" | ||
) |