Coder Social home page Coder Social logo

Parser generator about run-fig HOT 2 OPEN

clo4 avatar clo4 commented on June 11, 2024
Parser generator

from run-fig.

Comments (2)

clo4 avatar clo4 commented on June 11, 2024

This is the current idea that I have... I don't love it. Too complicated.

.
|- deno.json      // defines the build task
|- main.ts        // defines actions for commands, imports _parser.js
|- cli
|  |- spec.ts     // the spec definition file, purely declarative
|  |- _parser.js  // generated parser

from run-fig.

clo4 avatar clo4 commented on June 11, 2024

The main problem I have with this right now is that it separates the business logic from the CLI itself. This is probably okay but the possible DX is just worse imo.
The generated CLI either needs to be imported from the main file then have you hook into it so you can tell it what to run for each command, or have some kind of way to invoke an external function itself which feels too magical.

// cli_def.ts
import compile from "...";

compile("./cli_gen.ts", {
  name: "test",
  action: true,
  subcommands: [
    { name: "another", action: true },
  ],
});
// main.ts
import CLI from "./cli_gen.ts";

CLI.run({
  test: () => {},
  another: () => {},
});

I don't love this

What if instead main can also lazily define the CLI, so when called with a special command it'll compile instead of running

Keeps the definition and everything in one file, but introduces a bootstrapping problem

// main.ts
import CLI from "./cli_gen.ts";

CLI.spec("./cli_gen.ts", () => ({
  name: "something",
  subcommands: [
    { name: "wow" },
    { name: "non_idiomatic_name", run: "nonIdiomaticName" },
  ],
}));

CLI.run({
  something: () => {},
  wow: () => {},
  nonIdiomaticName: () => {},
});

This is maybe cleaner but it could get really bad for larger specs

from run-fig.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.