Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize the CLI structure ? #9

Closed
alexkharech opened this issue Sep 3, 2020 · 10 comments
Closed

Reorganize the CLI structure ? #9

alexkharech opened this issue Sep 3, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@alexkharech
Copy link
Contributor

I propose to reorganize the CLI structure, there are not many functions yet.
it would be wise to store commands in the map

import './commands/init/init.dart';
import './commands/create/project/project.dart';
import './commands/create/page/page.dart';
import './commands/create/view/view.dart';
import './commands/generate/locales/locales.dart';
import './commands/install/install.dart';
import './commands/version/version.dart';

const commands = {
  'init': initCommand,
  'create': {
    'project': createProjectCommand,
    'page': createPageCommand,
    'view': createViewCommand,
    ...
  },
  'generate': {
    'locales': generateLocalesCommand,
    ...
  },
  'install': installCommand,
  '-v', versionCommand, // change to `version`, to have the same structure everywhere?
  '-version', versionCommand, // and remove this alias?
  ...
};

// map for help in console 
const hints = {
  'init': 'generate the chosen structure on an existing project',
  'create': {
    'project': 'create a flutter project in the current directory',
    ...
  },
  ...
};

running the command can generate multiple files

./commands/create/page/samples/controller.dart
./commands/create/page/samples/binding.dart
./commands/create/page/samples/view.dart

Motivation:

  • All commands have one clear structure.
  • To add a new command, you need to create a separate independent directory.
  • Easily generate help in the console.
  • It is easy to check that the command exists and at this nesting level is a function.
  • Easy to expand functionality name unlimited command nesting.
@alexkharech
Copy link
Contributor Author

Commands should extend the abstract class, which is a generator and requires the implementation of the necessary functionality.

@CpdnCristiano CpdnCristiano added the enhancement New feature or request label Sep 3, 2020
@CpdnCristiano
Copy link
Collaborator

Over the weekend I will work on it

@CpdnCristiano
Copy link
Collaborator

I'm currently a little busy with other tasks

@alexkharech
Copy link
Contributor Author

maybe something similar?
i can help migrate existing features over the weekend

abstract class Command {
  /// hint for console
  String get hint;

  /// validate command line arguments
  bool validate();

  /// execute command
  Future<void> execute();
}

class ExampleCommand extends Command {
  String get hint => throw UnimplementedError();

  @override
  bool validate() {
    // TODO: implement validate
    throw UnimplementedError();
  }

  @override
  Future<void> execute() {
    // TODO: implement execute
    throw UnimplementedError();
  }
}

void main() {
  final commands = {
    'create': {
      'example': () => ExampleCommand(),
    }
  };

  final hints = {
    'create': {
      'example': ExampleCommand().hint,
    }
  };

  // find command by arguments
  final command = commands['...']['...']();

  // print errors
  if (command.validate()) {
    command.execute();
  }
}

@CpdnCristiano
Copy link
Collaborator

I am very grateful for your help

@alexkharech
Copy link
Contributor Author

@CpdnCristiano I have implemented the api I suggested. Where can I show an idea? this is from a clean project

@CpdnCristiano
Copy link
Collaborator

if you want you can create a repository on github

@alexkharech
Copy link
Contributor Author

https://github.com/alexkharech/get_cli_new_api

@CpdnCristiano
Copy link
Collaborator

very good, I liked it a lot I will implement it as soon as possible

@CpdnCristiano
Copy link
Collaborator

implemented some of your tips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants