-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pantani
authored and
Pantani
committed
Feb 9, 2024
1 parent
6088965
commit 5960000
Showing
9 changed files
with
406 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,78 @@ | ||
package cmd | ||
|
||
import "github.com/ignite/cli/v28/ignite/services/plugin" | ||
|
||
// GetCommands returns the list of wasm app commands. | ||
func GetCommands() []*plugin.Command { | ||
return []*plugin.Command{ | ||
{ | ||
Use: "wasm [command]", | ||
Short: "wasm is an awesome Ignite application!", | ||
Commands: []*plugin.Command{ | ||
{ | ||
Use: "hello", | ||
Short: "Say hello to the world of ignite!", | ||
}, | ||
}, | ||
}, | ||
import ( | ||
"github.com/ignite/cli/v28/ignite/pkg/cliui/colors" | ||
"github.com/ignite/cli/v28/ignite/pkg/xgenny" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
const ( | ||
flagPath = "path" | ||
|
||
statusScaffolding = "Scaffolding..." | ||
) | ||
|
||
var ( | ||
modifyPrefix = colors.Modified("modify ") | ||
createPrefix = colors.Success("create ") | ||
removePrefix = func(s string) string { | ||
return strings.TrimPrefix(strings.TrimPrefix(s, modifyPrefix), createPrefix) | ||
} | ||
) | ||
|
||
func flagGetPath(cmd *cobra.Command) (path string) { | ||
path, _ = cmd.Flags().GetString(flagPath) | ||
return | ||
} | ||
|
||
func flagSetPath(cmd *cobra.Command) { | ||
cmd.PersistentFlags().StringP(flagPath, "p", ".", "path of the app") | ||
} | ||
|
||
func sourceModificationToString(sm xgenny.SourceModification) (string, error) { | ||
// get file names and add prefix | ||
var files []string | ||
for _, modified := range sm.ModifiedFiles() { | ||
// get the relative app path from the current directory | ||
relativePath, err := relativePath(modified) | ||
if err != nil { | ||
return "", err | ||
} | ||
files = append(files, modifyPrefix+relativePath) | ||
} | ||
for _, created := range sm.CreatedFiles() { | ||
// get the relative app path from the current directory | ||
relativePath, err := relativePath(created) | ||
if err != nil { | ||
return "", err | ||
} | ||
files = append(files, createPrefix+relativePath) | ||
} | ||
|
||
// sort filenames without prefix | ||
sort.Slice(files, func(i, j int) bool { | ||
s1 := removePrefix(files[i]) | ||
s2 := removePrefix(files[j]) | ||
|
||
return strings.Compare(s1, s2) == -1 | ||
}) | ||
|
||
return "\n" + strings.Join(files, "\n"), nil | ||
} | ||
|
||
// relativePath return the relative app path from the current directory. | ||
func relativePath(appPath string) (string, error) { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return "", err | ||
} | ||
path, err := filepath.Rel(pwd, appPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
return path, nil | ||
} |
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"wasm/cmd" | ||
) | ||
|
||
func main() { | ||
if err := cmd.NewWasm().Execute(); err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.