Skip to content

Commit

Permalink
Merge pull request #164 from 5nord/add-modulepar-command
Browse files Browse the repository at this point in the history
Add list sub-command for module parameters
  • Loading branch information
moosq committed Feb 10, 2021
2 parents f781731 + 251d440 commit f12036b
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions internal/cmds/list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nokia/ntt/internal/ntt"
"github.com/nokia/ntt/internal/ttcn3/ast"
"github.com/nokia/ntt/internal/ttcn3/doc"
"github.com/nokia/ntt/internal/ttcn3/token"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -135,10 +136,11 @@ If a basket is not defined by an environment variable, it's equivalent to a
RunE: listTests,
}

listTestsCmd = &cobra.Command{Use: `tests`, RunE: listTests}
listModulesCmd = &cobra.Command{Use: `modules`, RunE: listModules}
listImportsCmd = &cobra.Command{Use: `imports`, RunE: listImports}
listControlsCmd = &cobra.Command{Use: `controls`, RunE: listControls}
listTestsCmd = &cobra.Command{Use: `tests`, RunE: listTests}
listModulesCmd = &cobra.Command{Use: `modules`, RunE: listModules}
listImportsCmd = &cobra.Command{Use: `imports`, RunE: listImports}
listControlsCmd = &cobra.Command{Use: `controls`, RunE: listControls}
listModuleParsCmd = &cobra.Command{Use: `modulepars`, RunE: listModulePars}

w = bufio.NewWriter(os.Stdout)

Expand All @@ -155,7 +157,7 @@ func init() {
Command.PersistentFlags().StringSliceVarP(&baskets[0].nameExclude, "exclude", "x", []string{}, "exclude objects matching regular * expresion.")
Command.PersistentFlags().StringSliceVarP(&baskets[0].tagsRegex, "tags-regex", "R", []string{}, "list objects with tags matching regular * expression")
Command.PersistentFlags().StringSliceVarP(&baskets[0].tagsExclude, "tags-exclude", "X", []string{}, "exclude objects with tags matching * regular expression")
Command.AddCommand(listTestsCmd, listModulesCmd, listImportsCmd, listControlsCmd)
Command.AddCommand(listTestsCmd, listModulesCmd, listImportsCmd, listControlsCmd, listModuleParsCmd)
}

type basket struct {
Expand Down Expand Up @@ -342,6 +344,40 @@ func listControls(cmd *cobra.Command, args []string) error {
return nil
}

func listModulePars(cmd *cobra.Command, args []string) error {
for _, info := range infos {
if info.Err != nil {
return info.Err
}
ast.Inspect(info.Module, func(n ast.Node) bool {
if n == nil {
return false
}
switch n := n.(type) {
case *ast.ValueDecl:
if n.Kind.Kind == token.MODULEPAR || n.Kind.Kind == token.ILLEGAL {
return true
}

return false

case *ast.Declarator:
name := info.Module.Name.String() + "." + n.Name.String()
tags := doc.FindAllTags(ast.FirstToken(n).Comments())
if !match(name, tags) {
return false
}
printItem(info.FileSet, n.Pos(), tags, name)

case *ast.Module, *ast.ModuleDef, *ast.GroupDecl, *ast.ModuleParameterGroup:
return true
}
return false
})
}
return nil
}

func printItem(fset *loc.FileSet, pos loc.Pos, tags [][]string, fields ...string) {

if verbose {
Expand Down

0 comments on commit f12036b

Please sign in to comment.