Skip to content

stdin does not allow further switches #94

Closed

Description

@ilanpillemer

./mme -extract -model=DEVAL_12 > temp2.kts; ./mm temp2.kts -graph works
./mme -extract -model=DEVAL_12 | ./mm - -graph does not work.

where mm is the DSL.

note running ./mme -extract -model=DEVAL_12 | ./mm - does half work, but not very useful as I need the switch.

Activity

  1. holgerbrandl commented on Jan 17, 2018

    @holgerbrandl
    Collaborator

    I've tested test_script.kts - -graph with

    #!/usr/bin/env kscript
    
    println("arugment test")
    
    for (arg in args) {
        println("arg: $arg")
    }

    to make sure that arguments are correctly forward to the script, which seems the case.
    So if stream processing fails if the option is provided, I'd suspect rather some issue with your script logic.

    Could you simplify/share temp2.kts to help me reproducing the problem?

  2. ilanpillemer commented on Jan 17, 2018

    @ilanpillemer
    ContributorAuthor

    The issue is happening somehow in the preamble bash file. The kts file is piped into a preamble bash file.

  3. ilanpillemer commented on Jan 17, 2018

    @ilanpillemer
    ContributorAuthor
    #!/usr/bin/env bash
    
    
    export CUSTOM_KSCRIPT_NAME='mm'
    
    export CUSTOM_KSCRIPT_PREAMBLE='
    // declare dependencies
    #!/usr/bin/env kscript
    
    
    //DEPS com.eclipsesource.minimal-json:minimal-json:0.9.4
    
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/Command.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/SemanticModel.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/Config.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/MetaParser.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/DslInterpreter.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/DslParser.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/BrixApi.kt
    //INCLUDE /Users/ilanpillemer/git/model-language/src/main/kotlin/Brix/BrixParser.kt
    
    // also adjust jvm settings
    // @file:KotlinOpts("-J-Xmx5g")
    
    USERNAME = "'"$MMDSL_USERNAME"'"
    PASSWORD = "'"$MMDSL_PASSWORD"'"
    BASEURL = "'"$MMDSL_BASEURL"'"
    // define some important variables to be used throughout the dsl
        if (args.size > 0) {
            if (args.contains("-graph-measure")) showGraphMeasure = true
            if (args.contains("-graph-measures")) showGraphMeasure = true
            if (args.contains("-graph-network")) showGraphNetwork = true
            if (args.contains("-graph")) showGraphComplete = true
            if (args.contains("-create-model")) createNewModel = true
            if (args.contains("-syntax-tree")) showSyntaxTree = true
            if (args.contains("-symbol-table")) showSymbolTable = true
            if (args.contains("-symbols")) showKeys = true
            if (args.any({ s -> s.startsWith("-user") })) {
                USERNAME = args.first( { s -> s.startsWith("-user") } ).split("=")[1]
            }
            if (args.any({ s -> s.startsWith("-password") })) {
                PASSWORD = args.first( { s -> s.startsWith("-password") } ).split("=")[1]
            }
            if (args.any({ s -> s.startsWith("-baseurl") })) {
                BASEURL = args.first( { s -> s.startsWith("-baseurl") } ).split("=")[1]
            }
        }
    
    var foo = "bar"
    '
    
    ~/git/kscript/kscript $@
    
  4. hj-lee commented on Feb 6, 2018

    @hj-lee
    Contributor

    It looks like kscript treats "-" as one of kscript options, not as the script.
    Below code in Kscript.kt seems to be the culprit.

    val userArgs = args.dropWhile { it.startsWith("-") }.drop(1)

    Changing it to something like below would fix the issue.

    val userArgs = args.dropWhile { it.startsWith("-") && it != "-" }.drop(1)
  5. ilanpillemer commented on Feb 6, 2018

    @ilanpillemer
    ContributorAuthor

    I will give that a try this week and see if it works. And if it does put together a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions