sporniket / ideas

My backlog of ideas, organized as a bunch of issues
0 stars 0 forks source link

Générateur d'interfaces en lignes de commandes #24

Open sporniket opened 1 year ago

sporniket commented 1 year ago

Description

CLU pour 'Command Line Utility', petit clin d'œil à Tron

Un utilitaire en python pour générer, à partir d'un descripteur, une interface en lignes de commandes en shell bash comme pour le projet sporny-wrecking-ball.

Ainsi, pour le projet mentionné, le descripteur aurait un contenu de ce genre :

_Il manque une spécification pour la génération de l'environnement à sourcer (. env_file_to_source)_

{
  "project":{
    "command":"ap",
    "name":"Assemble Project, by Sporniket",
    "version":"0.0.0-SNAPSHOT"
  },
  "env":[
    {
      "CLI_DIR":"${BASEDIR}/zz_cli",
      "BUILD_DIR":"${BASEDIR}/zz_build",
      "ARTIFACT_DIR":"${BASEDIR}/zz_artifacts"
    }
  ],
  "commands":[
    {
      "name":"install",
      "help":"Install vasm, Hatari,...",
      "type":"subcommands",
      "items":[
        {
          "name":"vasm",
          "help":"VASM, a portable and retargetable assembler.",
          "type":"execute",
          "exec":[
            "${CLI_DIR}/scripts/install_vasm.bash",
            "${BUILD_DIR}/vasm",
            "${ARTIFACT_DIR}/opt"
          ]
        },
        {
          "name":"hatari",
          "help":"Hatari, an Atari ST/STE/TT/Falcon emulator.",
          "type":"execute",
          "exec":[
            "${CLI_DIR}/scripts/install_hatari.bash",
            "${BUILD_DIR}/hatari",
            "${ARTIFACT_DIR}/opt"
          ]
        }
      ]
    },
    {
      "name":"setup",
      "help":"Setup utility.",
      "type":"execute",
      "exec":[
        "${CLI_DIR}/scripts/setup_ap.bash",
        "${BASEDIR}"
      ]
    },
    {
      "name":"scandeps",
      "help":"Scan source files into makefile dependencies variables.",
      "type":"execute",
      "exec":[
        "${CLI_DIR}/scripts/scandeps.bash"
      ]
    },
    {
      "name":"build",
      "help":"Build utility.",
      "type":"subchoice",
      "items":[
        "swb",
        "fontext",
        "fontgen",
        "lvlgen",
        "sheetext",
        "checkhw",
        "ci",
        "all"
      ],
      "exec":[
        "${CLI_DIR}/scripts/build.bash",
        "${2}"
      ]
    },
    {
      "name":"run",
      "help":"Run utility.",
      "type":"subchoice",
      "items":[
        "swb",
        "sheetext",
        "ci",
        "desktop"
      ],
      "exec":[
        "${CLI_DIR}/scripts/run.bash",
        "${2}"
      ]
    }
  ]
}

Invocation type

python3 -m clu ./my/cli/description.json

Si l'alias est utilisé :

clu ./my/cli/description.json

Fichiers produits

sporniket commented 1 year ago

génération de la selection

def genCommand(commands, *, indent="", selector=1, prefix=''):

  print(f"{indent}case \"${selector}\" in")
  indent = f"{indent}  "

  for item in commands:
    print(f"{indent}{item.name})"
    if item.type == "execute":
      print(f"  {indent}  {" ".join("\""+item.exec+ "\"")})"
      print(f"  {indent}  ;;)"
    elif item.type == "subcommand":
      genCommand(item.items, indent=indent, selector=2, prefix = "_".join([prefix,item.name]))
    elif ...:
      doStuff()
    print (f"{indent}  *)")
    print (f"{indent}    {prefix}_help")
    print (f"{indent}    ;;")
    print (f"{indent}    ;;")
    print (f"{indent}esac")