-
Notifications
You must be signed in to change notification settings - Fork 81
feat: add plugin command #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
waiting for PR: go-flutter-desktop/hover#28
The following workflow works:
Tada the platform version is displayed! |
1b08475
to
c897ac5
Compare
Wow this looks great! |
cmd/plugins.go
Outdated
} | ||
|
||
var pluginCleanCmd = &cobra.Command{ | ||
Use: "clean", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean
is often used as subcommand to remove everything that was created by the parent command. In this case, a user may expect hover plugin clean
to remove everything that hover plugin get
added. This may be confusing. I like how Go went with tidy
(go mod tidy
). It implies some stuff may be removed, but only when it was not needed anymore. Maybe we can go with hover plugin tidy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this proposition!
cmd/plugins.go
Outdated
} | ||
|
||
var pluginCmd = &cobra.Command{ | ||
Use: "plugin", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hover plugin get
, hover plugin list
..
It feels a little bit like we're letting hover work on a plugin that was created with init-plugin
...
A project can have multiple plugins. So should this subcommand maybe be plural?
hover plugins get
, hover plugins list
?
cmd/plugins.go
Outdated
|
||
res, getErr := client.Do(req) | ||
if getErr != nil { | ||
return remoteList.List, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning err (which is nil at this point) when getErr
is not nil. Why don't just name the err err
instead of getErr
?
cmd/plugins.go
Outdated
|
||
body, readErr := ioutil.ReadAll(res.Body) | ||
if readErr != nil { | ||
return remoteList.List, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here, readErr
vs err
cmd/plugins.go
Outdated
remoteList := &onlineList{} | ||
|
||
client := http.Client{ | ||
Timeout: time.Second * 5, // Maximum of 5 secs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is maybe a little bit low for some people on bad connections?
cmd/init-plugin.go
Outdated
fmt.Println("hover: A file or directory named `" + buildPath + "` already exists. Cannot continue init-plugin.") | ||
os.Exit(1) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err can still be not nil, currently only os.IsExist(err) scenario is handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooww man, that not fair!
you can only blame you on that one^^ 😉
cmd/init-plugin.go
Outdated
} | ||
|
||
if _, ok := getPubSpec().Flutter["plugin"]; !ok { | ||
fmt.Println("hover: The directory doesn't appear to contain a plugin package. To create a flutter plugin, use `flutter create --template=plugin`.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users probably still need to run hover after they create the flutter plugin, because they want to have a hover plugin.
Maybe change to: "To create a new plugin, first run flutter create --template=plugin
, then run hover init-plugin
."
cmd/plugins.go
Outdated
|
||
"github.com/go-flutter-desktop/hover/internal/fileutils" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports need sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to myself: never add newlines in import statements, it messes gofmt
cmd/plugins.go
Outdated
"github.com/spf13/cobra" | ||
) | ||
|
||
var standaloneImplementationListAPI = "https://github.com/raw/go-flutter-desktop/plugins/master/list.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be a const?
cmd/plugins.go
Outdated
path, err := filepath.Abs(filepath.Join(dep.path, "go")) | ||
if errParse != nil { | ||
err = errParse | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand? Why not check err
before the filepath.Abs line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I need some go advice here.
The following warning message needs to be printed if readPluginGoImport
or/and filepath.Abs
are returning an error.
How do I don't duplicate the fmt.Printf ... warning...
message without introducing a new function/goto..
What is the idiomatic way to handle errors in this context?
9bed8a2
to
42d1ddf
Compare
42d1ddf
to
708abff
Compare
I've fucked up my rebase so hard that I had to start from scratch. |
Feature run-down
hover init-plugin github.com/my-organization/plugin_name
initialize the current directory (must be a flutter plugin) with go support.The files added are:
go.mod go.sum import.go.tmpl plugin.go README.md
All of them (except go.mod|sum) are generated based on the current pubspec.yaml.
go/cmd
upon plugin import.hover init
will check for 'lib/main_desktop.dart' file and add it if asked.hover init
executehover plugin list
hover plugin list
list golang platform plugin available (--all
to also show the one without golang support)hover plugin get
will add go platform plugin by using the import.go.tmpl of that plugin (--force
to re-add plugins) (respect flutter pubspec.yaml/dev_dependencies/plugin_name/path, by adding the correct replace in the 'go.mod' file (this part is done by applying a regex on the import.go.tmpl file in order to obtain the go module name)) (--dry-run
performs a trial run with no changes made.)hover plugin clean
will remove unused plugin (has been added and removed from pubspec.yaml) (--purge
to remove used plugin) (try to clean the 'go.mod' file, but it's not mandatory, as it doesn't affect golang compilation) (--dry-run
performs a trial run with no changes made.)hover run
will apply the same check asflutter build ..
do with the automaticRunning "flutter pub get" in ...
. This check is used to suggest go platform plugin import.hover plugin
uses the local pub cache & a hosted json mapping list to look for golang pluginfixes: go-flutter-desktop/go-flutter#260
fixes: go-flutter-desktop/go-flutter#143