loentar / ngrest

Fast and easy C++ RESTful WebServices framework
Apache License 2.0
464 stars 93 forks source link

"ngrest create -d hpp" does not work #96

Closed Theophobia closed 1 year ago

Theophobia commented 1 year ago

Hi,

After installing I could not create a project with a service within a single .hpp file using the command ngrest create -d hpp <project_name>

Uninstalling and following the installation instructions did not help me:

[theophobia:~]$ rm -Rf ~/.ngrest 
[theophobia:~]$ sudo rm /usr/local/bin/ngrest
[theophobia:~]$ wget -qO- http://bit.ly/ngrest | bash
Cloning into 'ngrest'...
remote: Enumerating objects: 2320, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 2320 (delta 5), reused 13 (delta 2), pack-reused 2296
Receiving objects: 100% (2320/2320), 863.07 KiB | 99.00 KiB/s, done.
Resolving deltas: 100% (1379/1379), done.
Configuring ngrest for the build...
// many CMake Deprecation Warnings removed from here //

Skipping Nginx module compilation: no Nginx source path provided
Building ngrest. It may take few minutes...
// warnings during build removed, no errors //

Build OK
Installing ngrest script into /usr/local/bin/
Installation completed.

Now you can create your first project by typing:

  ngrest create myproject

[theophobia:~]$ ngrest                               
run: No ngrest projects found in current directory.

To create a new ngrest project:
  ngrest create <project_name>

For more help, see "ngrest help".
[theophobia:~]$ ngrest create -d hpp users
Creating project [-d] with services [hpp]...
mkdir: invalid option -- 'd'
Try 'mkdir --help' for more information.
Failed to create directory for project [-d]

However, creating normally results in a functioning project:

[theophobia:~]$ ngrest create users       
Creating project [users] with services [users]...

Your new project [users] has been created.

To start it please cd to "users" and type:

  ngrest

[theophobia:~]$ cd users
[theophobia:~/users]$ ll
Permissions Size User       Date Modified Name
.rw-r--r--  2.7k theophobia 21 Nov 09:40  CMakeLists.txt
drwxr-xr-x     - theophobia 21 Nov 09:40  users

[theophobia:~/users]$ ngrest
Building project users...
// some CMake Deprecation Warnings //
build finished.

To test your services try ngrest service tester:
  http://localhost:9098/ngrest/service/users

Starting your project in local deployment mode...
Press [Ctrl+C] to stop your project

Watching your project for modifications...

I/21-11-2022 09:41:22.120 Server startup time: 1.071ms
I/21-11-2022 09:41:22.120 Simple ngrest server started on port 9098.
I/21-11-2022 09:41:22.120 Deployed services: http://localhost:9098/ngrest/services

Running Arch Linux x86_64 on 5.15.79-1-lts, all packages up to date. Some time ago I remember being able to create a service in a single .hpp file, has something changed or am I doing something wrong?

Regards, Theophobia

loentar commented 1 year ago

It seems like a bug, if you edit ngrest script inlining the content of parse_codegen_options function to two places it would work:


create() {
  CODEGEN_OPTIONS=
  if [ "x${1::1}" = "x-" ]
  then
    case "${1:1:1}" in
      d)
        OPT=${1:2}
        if [ -z "$OPT" ]
        then
          if [ -z "${2:-}" ]
          then
            echo "Missing option for -d" >&2
            exit 1;
          fi
          OPT=$2
          shift
        fi
        CODEGEN_OPTIONS+=",$OPT"
        ;;
    esac
    shift
  fi

  if [ -z "$1" ]
  then
    echo "Project name omitted" >&2
    help_create
    exit 1
  fi
...
Theophobia commented 1 year ago

Replacing parse_codegen_options $@ with the function itself in addservice() and create() seemed to work.

Thank you!