Class: Mnenv::Shells::CmdShell

Inherits:
BaseShell show all
Defined in:
lib/mnenv/shells/cmd.rb

Overview

CMD/Batch shell implementation (Windows)

Instance Method Summary collapse

Instance Method Details

#config_fileObject



99
100
101
# File 'lib/mnenv/shells/cmd.rb', line 99

def config_file
  nil # CMD doesn't have a standard config file
end

#nameObject



9
10
11
# File 'lib/mnenv/shells/cmd.rb', line 9

def name
  'cmd'
end

#shim_content(executable_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mnenv/shells/cmd.rb', line 17

def shim_content(executable_name)
  <<~SHIM
    @echo off
    rem mnenv shim for CMD

    if defined MNENV_ROOT (
      set "MNENV_ROOT=%MNENV_ROOT%"
    ) else (
      set "MNENV_ROOT=%USERPROFILE%\\.mnenv"
    )

    rem Resolve version and source
    set "VERSION="
    set "SOURCE="

    rem Check environment variables first
    if defined METANORMA_VERSION set "VERSION=%METANORMA_VERSION%"
    if defined METANORMA_SOURCE set "SOURCE=%METANORMA_SOURCE%"

    rem Check local .metanorma-version file
    if not defined VERSION (
      set "DIR=%CD%"
      :loop
      if exist "%DIR%\\.metanorma-version" (
        set /p VERSION=<"%DIR%\\.metanorma-version"
        goto :found_version
      )
      for %%I in ("%DIR%\\..") do set "PARENT=%%~fI"
      if "%PARENT%"=="%DIR%" goto :check_global
      set "DIR=%PARENT%"
      goto :loop
    )

    :check_global
    if not defined VERSION (
      if exist "%MNENV_ROOT%\\version" (
        set /p VERSION=<"%MNENV_ROOT%\\version"
      )
    )

    :found_version
    if not defined SOURCE (
      if exist "%MNENV_ROOT%\\source" (
        set /p SOURCE=<"%MNENV_ROOT%\\source"
      )
    )

    rem Default source
    if not defined SOURCE set "SOURCE=gemfile"

    if not defined VERSION (
      echo mnenv: version not set or invalid 1>&2
      echo Set a version with: mnenv global ^<version^> or mnenv local ^<version^> 1>&2
      exit /b 1
    )

    rem Determine executable path based on source
    rem Installed versions are in %MNENV_ROOT%\\installed\\<version>-<source>\\
    if "%SOURCE%"=="binary" (
      set "EXECUTABLE=%MNENV_ROOT%\\installed\\%VERSION%-%SOURCE%\\metanorma.exe"
    ) else (
      set "EXECUTABLE=%MNENV_ROOT%\\installed\\%VERSION%-%SOURCE%\\bin\\#{executable_name}.cmd"
    )

    if not exist "%EXECUTABLE%" (
      echo mnenv: #{executable_name} not installed for version %VERSION% ^(source: %SOURCE%^) 1>&2
      echo Install it with: mnenv install %VERSION% --source %SOURCE% 1>&2
      exit /b 1
    )

    call "%EXECUTABLE%" %*
  SHIM
end

#shim_extensionObject



13
14
15
# File 'lib/mnenv/shells/cmd.rb', line 13

def shim_extension
  '.bat'
end

#use_output(version, source) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/mnenv/shells/cmd.rb', line 91

def use_output(version, source)
  lines = []
  lines << "set METANORMA_VERSION=#{version}"
  lines << "set METANORMA_SOURCE=#{source}" if source
  lines << 'rem Run this in your CMD session'
  lines.join("\n")
end

#windows?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/mnenv/shells/cmd.rb', line 103

def windows?
  true
end