Skip to content

Bug with the dig function #7

@mac10688

Description

@mac10688
  let rec private dig argv (cmd: Command<int>) =
    let config = (cmd.config CommandInfo.empty)
    match argv with
      | [] -> (cmd, [])
      | args ->
        match config.options |> List.choose (fun o -> o.isMatch args)
                             |> List.tryHead with
          | Some rest -> dig rest cmd
          | None ->
            match config.subcommands |> List.tryFind (fun sc -> sc.Summary().name = List.head args) with
              | Some sc -> dig (List.tail args) sc
              | None -> (cmd, args)

I think

        match config.options |> List.choose (fun o -> o.isMatch args)
                             |> List.tryHead with
          | Some rest -> dig rest cmd

will be the cause of infinite recursion.

Really I am trying to write a unit test for the generator function, which calls the dig method and I'm trying to rationalize what it's supposed to do. I don't understand how isMatch is supposed to work. It sounds like something that would return a boolean but instead it returns an option of list of strings?

Here is my first pass at seeing how the generator function works and it hit infinite recursion.

[<Test>]
let generator () =

    let commandSummary  = {
        name = "Name"
        displayName = Some "DisplayName"
        description = "Test description"
        paramNames = None
        help = None
        genSuggestions = fun _ -> []
    }

    let commandOption1 = {
        names = ["commandOptionName1"]
        description = "description"
        isFlag = false
        paramNames = [["paramNames1"]]
        isMatch = fun _ -> Some ["Matches"]
        genSuggestions = fun _ -> []
    }

    let commandOption2 = {
        names = ["commandOptionName2"]
        description = "description"
        isFlag = false
        paramNames = [["paramNames2"]]
        isMatch = fun _ -> Some ["Matches"]
        genSuggestions = fun _ -> []
    }

    let command1 = {
        config = fun _ -> {
            summary = {
                name = "SubName1"
                displayName = Some "SubDisplayName1"
                description = "Sub Test description 1"
                paramNames = Some ["SubTest1"; "SubParams1"]
                help = None
                genSuggestions = fun _ -> []
            }
            options = []
            subcommands = []
        }
        func = fun args -> (0, args)
    }

    let command2 = {
        config = fun _ -> {
            summary = {
                name = "SubName2"
                displayName = Some "SubDisplayName2"
                description = "Sub Test description 2"
                paramNames = Some ["SubTest2"; "SubParams2"]
                help = None
                genSuggestions = fun _ -> []
            }
            options = []
            subcommands = []
        }
        func = fun args -> (0, args)
    }

    let commandInfo = {
        summary = commandSummary
        options = [commandOption1; commandOption2]
        subcommands = [command1; command2]
    }

    let cmd = {
        config = fun _ -> commandInfo
        func = fun args -> (5, args)
    }

    let x = Generators.Help.generate [""] cmd 
    x |> should equal [""]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions