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

CLI - First draft #455

Open
wants to merge 33 commits into
base: testing
Choose a base branch
from
Open

CLI - First draft #455

wants to merge 33 commits into from

Conversation

fleischie
Copy link

@fleischie fleischie commented Sep 5, 2016

Hello ckb community. 👋

I started to implement a command line interface as an alternative frontend for the ckb application some time ago, but never got the time to really finish it. But as I noticed the project did get some attention (mostly negative after the new devices were introduced), so I thought I make my cli-draft publicly available to show some support for the project and the developers as well as to articulate the problems of having to implement something while having not much time.

I appreciate comments and feedback. 😊

As for the branch:
This branch introduces a possibility to control the ckb application via the command line: Use the --cmd flag to execute a given command. The syntax is specified in the cli-specs.md file, I suppose the in-command documentation (when passing an invalid command I mean) is not as polished, yet (as for example the ip command, which I took as an example on how to display the syntax).

Currently only the global commands are available, these include:

  • global info
  • global layout
  • global modifier
  • global framerate
  • global animation-dir
  • global brightness-per-mode
  • global spatial-dithering
  • global firmware-autocheck
  • global tray-icon
  • global mouse-acceleration
  • global scroll-acceleration
  • global scroll-acceleration-speed
  • global long-macro-delay

If you want to try this branch out, these steps must be taken prior to running commands:
0. Navigate to the root dir: `cd ckb/.

  1. Start the ckb-daemon:sudo bin/ckb-daemon.
  2. Start the GUI in another window:bin/ckb -b.
  3. Run a command:bin/ckb --cmd global info.

As to why the Gui has to be running for performing commands on the cli, please refer to the discussion in Issue #213.

I didn't start the device and profile commands as I do not know, whether to implement the current structure or wait for the new structure of only having global profiles, which are applied to all devices. Also I appreciate any input. 😄

cc @ccMSC

fleischie added 30 commits June 4, 2016 22:06
Using 4 spaces as levels of indentation:
* Use another level of indentation for the case-statements.
* Use two levels of indentation for wrapped arguments.
The 'cli-specs.md' file gathers all information for implementing the
CLI. It states the (currently) supported operations as well as a grammar
to understand.

This file should help keep track of necessities to implement and
idiosyncrasies to consider.
Add stubs to parse a `-x`, `--cmd` and `--execute` options.
* Add CommandLineOptions to catch these cases.
* Add CommandLine stub class in 'cli.h'/'cli.cpp' files.
* Add these files to 'ckb.pro'.
Move cli-command handler in main program to pass through the
background handler. This way the ckb program is automatically run in
background on executing a cli command.

This was discussed in issue #213.
To handle potential errors in cli operations by adding result codes,
that can be returned to the main program.

* Add enum to header definitons of the CommandLine class.
* Return the `CommandLineOK` code by default.
* Read return code of CommandLine in main routine.
As mentioned in issue #300 the cli should allow for printing all
macro key definitions of the specified profile.
Omit warning, that ckb is already running, if command line command was
issued.
In `execute()` split the arguments into base, flag and commands. Run the
specified commands in the `run()` method.

* Add `base`, `flag` and `commands` members.
* Populate these members in the static `execute()` method.
* Run the requested operations within the `commands` member in the new
  `run()` method. (Which is a stub at this point.)
This commit reverts some changes made in commit 9d06264.

Remove one level of indentation for the case statements. This is done to
ensure consistency with the project, instead of some coding convention.
Add class to track the selected command to execute.

* Add identifiers to specify which command to execute.
* Add method to differentiate and resolve command identifiers.
* Read in strings from commandList.
* For debugging purposes print, what to do.
* Inline `resolveCommand` querries to be more concise.
* Let `CommandLine` methods return `CommandLine` status codes.
* Remove excessive calls to `.toLocal8Bit().data()`.
Resolve layout input to `KeyMap::Layout` specifier.
Replace all iostream-operations (`std::cout << ... << std::endl;`) with
calls to `qDebug()`.
Coerce command to lower case before comparison to enable
case-insensitive cli commands.
Use the already implemented `getLayout` method of the `KeyMap` class to
resolve the correct layout.
Create a static `QTextStream` instance, that can be used similarily to
`qDebug()`, etc. and helps printing text to the command line.

NOTE: See http://stackoverflow.com/questions/3886105/\
                 how-to-print-to-console-when-using-qt for a discussion
      of the general idea.
* Add `CommandLine` class as friend to `KbManager` class access
  `scanDevices()` method.
* Add calls to initialize KbManager instance and scan for devices.
* Create the deviceLabel similar to the way it's done in the main
  window.
* Build information string and print it to the console.
* Encapsulate CommandInfo command in brackets to enable several cases.
* List all available layout names + codes, highlighting the currently
  selected one with "global layout list".
* Set new layout with the given layout code, if valid, persistently
  saving it via `CkbSettings` instance.
* Make `Command::runGlobal()` return `CommandLineUnknown`, instead of
  `Command::CommandUnknown`.
* Coerce layout's task command to lower case, to enable case insensitive
  invocation.
* Fix comment's grammar.
Use `KbBind` class to read and set the global key bindings. Allow
setting of OS X specific keys, by handling appropriate edge cases.
Show frame rate from `CkbSettings` class, set it using `Kb` and store it
via `CkbSettings` as well, showing all appropriate warnings.
Scan and display information about the animations directory/directories.
Use `KbLight` and `CkbSettings` class to display information about
shared dimming and persistently set it's status.
Use `Kb` and `CkbSettings` class to display information about spatial
dithering and persistently set it's status.
Use `CkbSettings` class to display information about the status of the
autocheck feature of the firmware and persistently set it's status.
Use `CkbSettings` class to display information about tray icon and
persistently set it's status.
Use `Kb` and `CkbSettings` class to display information about mouse
acceleration and persistently set it's status.
Use `Kb` and `CkbSettings` class to display information about scroll
acceleration and persistently set it's status.
Use `Kb` and `CkbSettings` class to display information about scroll
acceleration speed and persistently set it's status.
Add specification and parser for this command.

Use `Kb` and `CkbSettings` class to display information about the long
macro delay and persistently set it's status.
Remove the specification of empty device/profile commands, as they were not
updated after the discussion in issue #213 foreshadowed a major update
in the profile commands.

* Remove `ckb --cmd device`.
* Remove `ckb --cmd profile`.
Add value to identify invalid commands. Print the syntax for the
`global` command on these cases.

Only show the default help, if the command is unknown.
@h3
Copy link

h3 commented May 25, 2017

I need that !!

@ghost
Copy link

ghost commented Jan 30, 2018

It does sound very nice, indeed.

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

Successfully merging this pull request may close these issues.

2 participants