Skip to content

Commit

Permalink
Merge pull request #16 from slankdev/work
Browse files Browse the repository at this point in the history
pkg/vtyang: change -y <string> to -y <stringArray>
  • Loading branch information
slankdev committed May 3, 2024
2 parents 37e38cc + 361cd1e commit 1ad08fd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/vtyang/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AgentOptsBackendMgmtd struct {

type AgentOpts struct {
RuntimePath string
YangPath string
YangPath []string
LogFile string
// BackendMgmtd
BackendMgmtd *AgentOptsBackendMgmtd
Expand Down
2 changes: 1 addition & 1 deletion pkg/vtyang/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func TestFilterDbWithModule(t *testing.T) {
// Initializing Agent
if err := InitAgent(AgentOpts{
RuntimePath: GlobalOptRunFilePath,
YangPath: "./testdata/yang/frr_isisd_minimal",
YangPath: []string{"./testdata/yang/frr_isisd_minimal"},
LogFile: "/tmp/testlog.log",
}); err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vtyang/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
GlobalOptEnableGrpc bool
GlobalOptLogFile string
GlobalOptRunFilePath string
GlobalOptYangPath string
GlobalOptYangPath []string
GlobalOptDumpCliTree string
GlobalOptCommands []string
GlobalOptMgmtdSock string
Expand Down Expand Up @@ -115,7 +115,7 @@ func NewCommand() *cobra.Command {
fs.BoolVar(&GlobalOptEnableGrpc, "grpc", false, "Enable gRPC server")
fs.StringVarP(&GlobalOptLogFile, "logfile", "l", "/tmp/vtyang.log", "Log file")
fs.StringVarP(&GlobalOptRunFilePath, "run", "r", "", "Runtime file path")
fs.StringVarP(&GlobalOptYangPath, "yang", "y", "", "Yang file path")
fs.StringArrayVarP(&GlobalOptYangPath, "yang", "y", []string{}, "Yang file path")
fs.StringArrayVarP(&GlobalOptCommands, "command", "c", []string{}, "")
fs.StringVar(&GlobalOptMgmtdSock, "mgmtd-sock", "", "/var/run/frr/mgmtd_fe.sock")

Expand Down
34 changes: 17 additions & 17 deletions pkg/vtyang/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,27 +855,27 @@ func dumpCompletionTreeJson(root *CompletionNode) string {
return string(out)
}

func yangModulesPath(path string) (*yang.Modules, error) {
files, err := os.ReadDir(path)
if err != nil {
return nil, err
}

func yangModulesPath(paths []string) (*yang.Modules, error) {
modules := yang.NewModules()
for _, file := range files {
if file.IsDir() {
continue
}
if !strings.HasSuffix(file.Name(), ".yang") {
continue
}
fullname := fmt.Sprintf("%s/%s", path, file.Name())
log.Printf("loading yang module '%s'\n", fullname)
if err := modules.Read(fullname); err != nil {
for _, path := range paths {
files, err := os.ReadDir(path)
if err != nil {
return nil, err
}
for _, file := range files {
if file.IsDir() {
continue
}
if !strings.HasSuffix(file.Name(), ".yang") {
continue
}
fullname := fmt.Sprintf("%s/%s", path, file.Name())
log.Printf("loading yang module '%s'\n", fullname)
if err := modules.Read(fullname); err != nil {
return nil, err
}
}
}

errs := modules.Process()
if len(errs) > 0 {
for _, err := range errs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vtyang/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func executeTestCase(t *testing.T, tc *TestCase) {
// Initializing Agent
if err := InitAgent(AgentOpts{
RuntimePath: tc.RuntimePath,
YangPath: tc.YangPath,
YangPath: []string{tc.YangPath},
LogFile: tc.LogFile,
}); err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vtyang/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestDBNodeGet(t *testing.T) {
dbm.LoadDatabaseFromData(&testDummyDBRoot)

var err error
yangmodules, err = yangModulesPath("./testdata/yang/accounting")
yangmodules, err = yangModulesPath([]string{"./testdata/yang/accounting"})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestDBNodeCreate(t *testing.T) {
dbm.LoadDatabaseFromData(&testDummyDBRoot)

var err error
yangmodules, err = yangModulesPath("./testdata/yang/accounting")
yangmodules, err = yangModulesPath([]string{"./testdata/yang/accounting"})
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vtyang/xpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var xpathTestDBRoot = DBNode{

func TestXPathParseCli(t *testing.T) {
var err error
yangmodules, err = yangModulesPath("./testdata/yang/accounting")
yangmodules, err = yangModulesPath([]string{"./testdata/yang/accounting"})
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 1ad08fd

Please sign in to comment.